c# - MailAddress:在邮件 header 中发现无效字符

标签 c# .net email exception-handling mailaddress

我正在使用 MailAddress 创建传真电子邮件。 我们正在使用名为 SatisFAXtion v 8.6 的系统。 为了提供传真封面,我可以将模板位置添加到 mail.TO 地址。

格式如下:

12125551234^template=cp\\FAXReportCover.rtf@fax.ourcompanymail.com

编译时它工作正常,但我需要两个反斜杠,所以我又添加了两个作为转义字符。

当我运行程序时出现异常:

Message: An invalid character was found in the mail header:
StackTrace: at System.Net.Mail.MailAddressParser.ParseLocalPart(String data, Int32& index, Boolean expectAngleBracket, Boolean expectMultipleAddresses)
   at System.Net.Mail.MailAddressParser.ParseAddress(String data, Boolean expectMultipleAddresses, Int32& index)
   at System.Net.Mail.MailAddressParser.ParseMultipleAddresses(String data)
   at System.Net.Mail.MailAddressCollection.ParseValue(String addresses)
   at System.Net.Mail.MailAddressCollection.Add(String addresses)
   at System.Net.Mail.Message..ctor(String from, String to)
   at System.Net.Mail.MailMessage..ctor(String from, String to)

有没有办法在 MailAddress 对象的电子邮件地址中插入反斜杠?

最佳答案

来自 Wikipedia :

The restrictions for special characters are that they must only be used when contained between quotation marks, and that 3 of them (The space, backslash \ and quotation mark " (ASCII: 32, 92, 34)) must also be preceded by a backslash \ (e.g. "\ \\"").

因此,我认为您的电子邮件地址无效,因为引号中没有包含反斜杠。

如果您可以将地址更改为类似 12125551234^template="cp\\"FAXReportCover.rtf@fax.ourcompanymail.com 的地址,我认为可以。

关于c# - MailAddress:在邮件 header 中发现无效字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10334804/

相关文章:

c# - Entity Framework 6 : virtual collections lazy loaded even explicitly loaded on a query

c# - 与 LAN 上的应用程序通信

c# - .NET 计时器异步运行吗?

安卓 : email sending without google signing in (Automatically sending mails)

python - 在 post_save 上发送邀请电子邮件还是在 django View 中一次性发送邀请电子邮件?

c# - 将多个资源文件加载到一个资源管理器中

c# - Linq order by, group by 和 order by each group?

c# - 传递到字典中的模型项的类型为 'System.Data.Entity.DynamicProxies.People' ,但该字典需要类型为 的模型项

.net - .net 程序集 list 中是否提升了依赖项?

iPhone 自动发送应用内邮件