使用 SmtpClient 和 MailMessage 时如何抑制电子邮件验证
使用 SmtpClient 和 MailMessage (.net 3.5) 发送电子邮件时,“收件人”电子邮件地址在发送之前会得到验证。我有一大堆电子邮件地址,它们在 at 符号之前有一个点 (.),当您尝试使用 SmtpClient 发送消息时,会导致 FormatException。这实际上是一件好事,因为根据规范,at 符号之前的点是无效的。不幸的是,这些电子邮件存在于现实世界中,如果您使用您喜欢的电子邮件客户端发送它们,它们就会被送达。
我的问题是,可以禁止通过 SmtpClient/MailMessage 进行电子邮件验证吗?
When sending out emails using the SmtpClient and a MailMessage (.net 3.5) the "To" email address(es) get validated prior to sending. I've got a big stack of email addresses which have a dot (.) before the at-sign, causing a FormatException when you attempt to send the message using the SmtpClient. This is actually a good thing, because by specification a dot before the at-sign is invalid. Unfortunately, those emails exist in the real world and they get delivered, if you send them out using your preferred email client.
My question is, can email validation through the SmtpClient/MailMessage be suppressed?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试发送电子邮件后可能会出现错误。
您能否提供一些 CallStack,以便我们可以查看抛出异常的确切位置
更新:
根据reflector的反汇编代码,这个问题只能通过升级到VS2010和.NET 4.0来解决。
较低版本的System.Net程序集没有办法解决这个问题
This can be error after tring to send the e-mail.
Can you provide some CallStack so we can view where exactly exception is thrown
Update:
According to the disassemble code from reflector, this problem can be sold only by upgrading to the VS2010 and .NET 4.0
Lower versions of System.Net assembly have no way to solve this problem
编辑:尝试了 VB2005 中的示例代码,我也遇到了异常。下面的代码在 VB2010 Express 中运行良好,但似乎是一个错误,现已修复。 MSDN 引用来自 4.0 文档,该片段不在早期版本的 MSDN 页面中。
我现在无法尝试,但是您的电子邮件地址的格式到底如何? MailAddress 类的文档指出它支持用户名中的连续点和尾随点。例如,user...name..@host.(引用自 此处)。
编辑:添加示例。
Edit: Tried the sample code in VB2005 and I also got the exception. The code below works fine in VB2010 Express though so seems to be a bug that's now been fixed. The MSDN quote is from the 4.0 documenation, that snippet is not in the earlier versions of the MSDN page.
I can't try it right now but exactly how are your email addresses formatted? The documentation for the
MailAddress
class states that it supports Consecutive and trailing dots in user names. For example, user...name..@host. (quote copied from here).Edit: Added sample.