将电子邮件发送到 ASP.NET 中的文件夹
我想发送电子邮件文件夹而不是将电子邮件发送到网络。
我修改了 web.config
文件,而
<mailSettings >
<smtp deliveryMethod="SpecifiedPickupDirectory">
<specifiedPickupDirectory pickupDirectoryLocation="C:\Email"/>
</smtp>
</mailSettings>
</system.net>
我的代码是
SmtpClient client = new SmtpClient();
client.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;
问题是当我使用 client.发送它不会将电子邮件保存到文件夹中,而且我也没有收到任何错误。
那么我在这里缺少什么?
I want to send email folder instead to send emails to network.
I modified the web.config
file as
<mailSettings >
<smtp deliveryMethod="SpecifiedPickupDirectory">
<specifiedPickupDirectory pickupDirectoryLocation="C:\Email"/>
</smtp>
</mailSettings>
</system.net>
while my code is
SmtpClient client = new SmtpClient();
client.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;
The problem is that when I use client. Send it doesn't save emails to folder and also I don't get any error.
So what am I missing here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
看看Papercut。我已经品尝过它并阅读了很棒的评论。
Take at look at Papercut. I've sampled it and read great reviews.
您不需要在代码中修改
client.交付方法 - 这已经在 web.config 中设置并且是多余的 - 所以我要做的第一件事就是删除它。
Web 配置行看起来不错,但我会尝试 i) 在该文件夹规范中添加尾部斜杠,ii) 检查它是否存在,iii) 确保所需的进程有权写入它,以及 iv) 检查事件日志对于错误。
You don't need the lines in your code where you are modifying
client. Delivery Method
- this is already set in the web.config and is redundant - so the first thing I would do is remove that.The web config lines look ok, but I would try i) Adding a trailing slash to that folder specification, ii) Checking it exists, iii) Making sure that the required processes have permission to write to it, and iv) Checking the event logs for errors.
如果您将应用程序作为网络服务(IIS 中的默认设置)运行,那么它很可能没有对该文件夹的任何写入权限。尝试将其更改为本地系统,看看是否有帮助(仅用于测试,切勿将本地系统上下文用于生产)。
If you are running your application as Network Service (default in IIS) it's most likely it doesn't have any write permission to that folder. Try changing it to Local System and see if it helps (ONLY for testing, never use Local System context for production).