我想使用 Mandrill 发送消息。我需要以下代码来执行此操作:
将相同的消息发送给所有收件人,而无需每个收件人看到另一个收件人的地址。
我使用了以下代码:
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
string[] toResult = to.Split(new Char[] { ';' });
foreach (string s in toResult)
{
if (s != null && !s.Trim().Equals("") && !string.IsNullOrEmpty(s))
{
message.Bcc.Add(s);
}
}
if (!cc.Equals(""))
{
string[] ccResult = cc.Split(new Char[] { ';' });
foreach (string s in ccResult)
{
message.CC.Add(s);
}
}
if (!cci.Equals(""))
{
string[] cciResult = cci.Split(new Char[] { ';' });
foreach (string s in cciResult)
{
message.Bcc.Add(s);
}
}
message.Subject = subject;
message.From = new System.Net.Mail.MailAddress(from, from);
message.IsBodyHtml = true;
message.Body = "<html><body>" + body + "</body></html>";
message.BodyEncoding = System.Text.Encoding.UTF8;
System.Net.Mail.AlternateView plainView = System.Net.Mail.AlternateView.CreateAlternateViewFromString
(System.Text.RegularExpressions.Regex.Replace(body, @"<(.|\n)*?>", string.Empty), System.Text.Encoding.UTF8, "text/plain");
System.Net.Mail.AlternateView htmlView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(body, System.Text.Encoding.UTF8, "text/html");
message.AlternateViews.Add(plainView);
message.AlternateViews.Add(htmlView);
message.Priority = System.Net.Mail.MailPriority.Normal;
smtp.Host = smtpH;
bool ssl = false;
if (useSSL.Equals("true"))
ssl = true;
if (ssl)
{
smtp.EnableSsl = true;
}
else
{
smtp.EnableSsl = false;
}
smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
smtp.UseDefaultCredentials = false;
smtp.Credentials = new System.Net.NetworkCredential(userName, password);
smtp.Port = Convert.ToInt32(port);
message.Headers.Add("Message-Id", String.Concat("<", DateTime.Now.ToString("yyMMdd"), ".",
DateTime.Now.ToString("HHmmss"), "@" + from.Split('@')[1].ToString() + ">"));
smtp.Send(message);
正如您在上面的代码片段中看到的,我将所有电子邮件添加到密件抄送集合中,但它不起作用。
有没有人对这个问题有任何想法。