我正在使用 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/