发送邮件到多个收件人时如何修复异常? [英] How to fix exception thrown when sending mail message to multiple recipients?
问题描述
在下面的代码片段中,我在'this.Recipients'上得到一个FormatException。更具体地说,消息是在邮件头中找到无效的字符:';'。
In the code snippet below, I'm getting a FormatException on 'this.Recipients'. More specifically, the message is "An invalid character was found in the mail header: ';'".
收件人是一个由三个电子邮件地址组成的字符串,以分号分隔( ';'字符)。收件人列表从app.config中读取,数据正在进入收件人变量。
Recipients is a string of three email addresses separated by semicolons (the ';' character). The list of recipients is read from an app.config and the data is making it into the Recipients variable.
如果多个收件人应该分开,我该如何收到此错误用分号?有什么建议么?一如往常,谢谢你的帮助!
How can I be getting this error when multiple recipients should be separated by a semicolon? Any suggestions? As always, thanks for your help!
public bool Send()
{
MailMessage mailMsg =
new MailMessage(this.Sender, this.Recipients, this.Subject, this.Message);
SmtpClient smtpServer = new SmtpClient(SMTP);
smtpServer.DeliveryMethod = SmtpDeliveryMethod.Network;
编辑#1 - 这个表示使用分号。
Edit #1 - This says use a semicolon.
推荐答案
我看不到 MailMessage构造函数文档中的任何内容建议您可以指定多个收件人。我建议您创建 MailMessage
对象,然后分别添加每个电子邮件地址。
I can't see anything in the MailMessage constructor documentation to suggest you can specify multiple recipients like that. I suggest you create the MailMessage
object and then add each email address separately.
请注意, MailAddressCollection.Add
方法被记录为接受逗号 -separated地址...所以它可能可以在构造函数中工作。
Note that the MailAddressCollection.Add
method is documented to accept comma-separated addresses... so it's possible that that would work in the constructor too.
这篇关于发送邮件到多个收件人时如何修复异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!