可能重复:
无法使用 C# 向多个地址/收件人发送电子邮件
我使用下面的代码在脚本任务中发送邮件
string MailFromName = "Admin";
System.Net.Mail.SmtpClient mailobj = new System.Net.Mail.SmtpClient();
System.Net.Mail.MailAddress MailFrom = new System.Net.Mail.MailAddress(MailFromEmail, MailFromName);
System.Net.Mail.MailAddress MailTo = new System.Net.Mail.MailAddress(MailToEmail, MailToEmail);
System.Net.Mail.MailMessage mailmsg = new System.Net.Mail.MailMessage(MailFrom, MailTo);
mailmsg.IsBodyHtml = true;
mailmsg.Subject = strMessageSubject;
mailmsg.Body = strMessageBody;
mailobj.Host = strSMTPServerName;
mailobj.Send(mailmsg);
当我将 MailToEmail 用作“myaddress@myMail.com”即一个电子邮件地址时,它工作正常
但是当我有多个地址要列出时,这不会发送任何邮件(也不会失败)
例如:“MyAdress@MyMail.com;MySecondAddress@MyMail.com”
如何解决这个问题?
编辑新代码
string MailFromName = "Admin";
System.Net.Mail.SmtpClient mailobj = new System.Net.Mail.SmtpClient();
System.Net.Mail.MailAddress MailFrom = new System.Net.Mail.MailAddress(MailFromEmail, MailFromName);
System.Net.Mail.MailAddress MailTo = new System.Net.Mail.MailAddress(MailToEmail, MailToEmail);
System.Net.Mail.MailMessage mailmsg = new System.Net.Mail.MailMessage(MailFrom, MailTo);
mailmsg.IsBodyHtml = true;
mailmsg.Subject = strMessageSubject;
mailmsg.Body = strMessageBody;
foreach (string str in multipleToMsg)
{
mailmsg.To.Add(str);
}
mailobj.Host = strSMTPServerName;
mailobj.Send(mailmsg);