[英]C# MailMessage BCC property show address list in email when delivery
当我使用此代码时,当电子邮件发送时,密件抄送中的地址列表是可见的,为什么?
我使用.Net Framework 4.6.2
代码正常工作,它发送电子邮件但是当我检查收件人:在发送的电子邮件中,我可以看到我包含在 .Bcc.Add 中的所有收件人
密件抄送不像微软所说的那样工作?
public static bool SendEmails(string[] emailList, string from, string body, string subject, string attachment)
{
var result= false;
MailMessage email = null;
if (emailList!= null && !string.IsNullOrWhiteSpace(from))
{
email = new MailMessage
{
Priority = MailPriority.High,
From = new MailAddress(from),
Subject = subject,
Body = body,
BodyEncoding = Encoding.UTF8,
IsBodyHtml = true,
DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure,
};
if (!string.IsNullOrWhiteSpace(attachment))
{
email.Attachments.Add(new Attachment(attachment));
}
var smtp = new SmtpClient
{
Host = host,
Credentials =new System.Net.NetworkCredential("user","pass"),
EnableSsl = Convert.ToBoolean(ConfigurationManager.AppSettings["enablessl"]),
Port = int.Parse(ConfigurationManager.AppSettings["port"])
};
if (emailList.Count() > 0)
{
foreach (string email in emailList)
{
email.Bcc.Add(new MailAddress(email));
}
}
smtp.Send(email);
result= true;
}
return restul;
}
显然,在开始以密件抄送地址加载地址的循环之前,有必要在 emai.To.Add("anymail@anyhost.com") 中包含一封电子邮件,我不知道这是否有任何其他后果,但那是这个怎么运作。 电子邮件地址不再显示在已传递邮件的收件人:中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.