我想使用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);
正如您在上面的代码片段中看到的,我添加了Bcc集合中的所有电子邮件,但它不起作用.
有没有人对这个问题有任何想法.
解决方法:
如果人们仍然看到彼此的电子邮件地址,您可能希望转到帐户中的Sending Defaults页面并禁用将收件人彼此公开的选项.否则,您可以添加自定义SMTP标头以关闭该选项,但听起来您可能不希望默认启用该选项.