.NET SMTPClient - 待处理的外发邮件存储在哪里?
如果我已将一些电子邮件排队通过 System.Net.Mail.SMTPClent 发送,我在哪里可以找到该邮件? 对于 Windows SMTP 客户端,它位于 C:\inetpub\mailroot 文件夹中 - .NET 客户端是否有类似的文件夹?
编辑:这是一个例子。 如果我关闭 XP 计算机上的传出 SMTP 服务器,然后运行一个发送十几封电子邮件的应用程序,它们会在某处排队,因为 .NET SMTPClient.Send 调用成功。 几个小时后,我启动本地 SMTP 服务器,邮件突然匆忙离开。 与此同时它在哪里? 同样的行为也发生在我的 Vista 桌面上,尽管我没有本地 SMTP 服务器 - 我可以通过阻止防火墙上的端口 25 来复制该功能,然后邮件在某个地方排队。 在哪里?
这个问题的原因是我想在我拥有的服务器上重新启用 SMTP 服务,但我不知道在此期间排队的内容是什么,并且我想确保当我重新启用时队列是干净的启用该服务。 这样,客户就不会突然收到非常非常旧的排队电子邮件。
编辑:显然,我不知道我在说什么。 当我在 Vista 上执行此操作时:
Dim mm As New System.Net.Mail.MailMessage("[email protected]", "[email protected]", "Testing", "this is a test")
Dim s As New System.Net.Mail.SmtpClient("localhost")
s.DeliveryMethod = Mail.SmtpDeliveryMethod.PickupDirectoryFromIis
s.Send(mm)
我收到异常,因为我没有 IIS 拾取文件夹。 将其更改为“Mail.SmtpDeliveryMethod.Network”会立即导致异常,因为我没有运行 SMTP 服务器。 我将在服务器 2003 上对此进行测试,但我可以发誓这两者在过去都有效。 如果需要,我会做更多测试并修改问题。
If I've queued up some email to be sent via the System.Net.Mail.SMTPClent, where can I find this mail? With the Windows SMTP Client, it's in the C:\inetpub\mailroot folder - is there a similar folder for the .NET client?
EDIT: Here's an example. If I turn off the outgoing SMTP server on my XP computer and then run an application that sends a dozen emails, they get queued up somewhere, since the .NET SMTPClient.Send call succeeds. A few hours later, I start the local SMTP server, and the mail leaves in a sudden flurry. Where is it in the meantime? The same behavior happens on my Vista desktop, though I have no local SMTP server - I can duplicate the functionality by blocking port 25 on the firewall, and then mail queues up somewhere. Where?
The reason for this question is that I want to re-enable the SMTP Service on a server I have, but I don't know what's been queued up in the meantime, and I want to make sure the queue is clean when I re-enable the service. That way, customers don't get really, really old queued emails all of the sudden.
EDIT: Clearly, I don't know what I'm talking about. When I do this on Vista:
Dim mm As New System.Net.Mail.MailMessage("[email protected]", "[email protected]", "Testing", "this is a test")
Dim s As New System.Net.Mail.SmtpClient("localhost")
s.DeliveryMethod = Mail.SmtpDeliveryMethod.PickupDirectoryFromIis
s.Send(mm)
I get an exception because I don't have an IIS pickup folder. Changing it to "Mail.SmtpDeliveryMethod.Network" results in an immediate exception because I don't have an SMTP server running. I'll test this on server 2003, but I could have sworn that these both worked in the past. I'll do some more testing and modify the question if needed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
从 SmtpClient 的 MSDN 页面来看,它是可配置的。 您可以使用 DeliveryMethod 属性来决定是否立即发送邮件、是否将其排队到 IIS 拾取文件夹(大概是 C:\inetpub\mailroot)或是否将其放置在您选择的文件夹中(由 PickupDirectoryLocation 属性)。
From the looks of the MSDN pages for SmtpClient, it's configurable. You can use the DeliveryMethod property to decide whether mail is sent immediately, whether it's queued into the IIS pickup folder (presumably C:\inetpub\mailroot) or whether it's placed in a folder of your choosing (specified by the PickupDirectoryLocation property).
描述有点模糊,但是如果您调用
Send()
并且您的DeliveryMethod
是Network
并且调用成功,那么它不在.NET 领域不再存在。 某个东西已经接受了它的传递,并且它位于该东西的队列中,当您打开可以重新与外界连接的邮件服务器时,它会高兴地跳起来。 当DeliveryMethod为Network时,我很确定(至少从Reflector反汇编来看)它直接在网络流上书写,而不是通过一些中间临时文件。 如果它无法打开连接并获取该流,则会抛出异常。 这和我使用这个类的实际感受是吻合的。 希望有帮助。The description is a little vague, but if you call
Send()
and yourDeliveryMethod
isNetwork
and the call succeeds, then it's not in the realm of .NET anymore. Something has accepted it for delivery and it is sitting in that something's queue, which jumps for joy when you turn on the mail server that can connect with the outside world back on. WhenDeliveryMethod
isNetwork
, I'm pretty sure (at least, judging from the Reflector disassembly) that it's scribbling directly on a network stream and not via some intermediate temp file. If it couldn't open a connection and get that stream, then it vomits with an exception. This coincides with my actual experience in using this class. Hope that helps.默认情况下,SMTP 客户端使用网络发送。 因此,任何电子邮件都不会存储在任何地方。
这里是web.config的配置部分,
您可以看看这篇文章 显示了当
DeliveryMethod == SmtpDeliveryMethod.SpecifiedPickupDirectory
时如何手动处理 SMTP 客户端创建的文件。By default the SMTP client uses a network sending. So no emails are stored anywhere.
Here is the configuration section of the web.config
You can take a look to this article in code project which shows how to handle manually the files created by the SMTP Client when
DeliveryMethod == SmtpDeliveryMethod.SpecifiedPickupDirectory
.您可以设置指定的取货目录和配送方式,以实现更好的控制
You can set the specified pickup directory and delivery method for greater control
我习惯的 .NET SMTP 客户端不会在任何地方存储邮件。 它只是发送。 如果它应该发送的出站服务器已关闭,它会立即给出异常。
您已尝试在 XP 机器上打开和关闭出站服务器。 伟大的。 现在,尝试查找入站 SMTP 服务。 入站和出站 SMTP 服务通过 filedrop 相互通信。
The .NET SMTP client I'm used to doesn't store mail anywhere. It just sends. If the outbound server it is supposed to send through is down, it gives an exception immediately.
You've tried turning on and off the outbound server on your XP box. Great. Now, try to find the inbound SMTP service. The inbound and outbound SMTP services talk to each other by filedrop.