Sending letters with BCC list does not work

I am trying to send emails to one To recipient and a list of Hidden recipients. The Bcc recipient list is a list of strings, and they are successfully added to the MailMessage Bcc collection, but are not actually sent. If I add the same list to the "Cc" message collection, it works fine. Just not a Bcc collection. The code I use is as follows:

public void SendEmailMessage(String FromAddress, String ToAddress, String Subject, String Body, List<String> CCAddress, List<String> BccAddress, String Filepath) { using (SmtpClient mailClient = new SmtpClient()) { MailMessage mailMessage = new MailMessage(); mailMessage.From = new MailAddress(FromAddress); mailMessage.To.Add(new MailAddress(ToAddress)); foreach (String _email in CCAddress) { mailMessage.CC.Add(new MailAddress(_email)); } foreach (String _email in BccAddress) { mailMessage.Bcc.Add(new MailAddress(_email)); } mailMessage.Priority = MailPriority.Normal; mailMessage.Subject = Subject; if (Filepath != string.Empty) { Attachment _attachment = new Attachment(Filepath, MediaTypeNames.Application.Octet); mailMessage.Attachments.Add(_attachment); } AlternateView plainTextView = AlternateView.CreateAlternateViewFromString(GetTextonly(Body), null, "text/plain"); AlternateView htmlView = AlternateView.CreateAlternateViewFromString(Body, null, "text/html"); mailMessage.AlternateViews.Add(plainTextView); mailMessage.AlternateViews.Add(htmlView); SmtpClient smtpClient = new System.Net.Mail.SmtpClient(); smtpClient.Send(mailMessage); } } 

any ideas?

+1
source share
3 answers

One thing that I didn’t mention is that mail is placed in the pickup directory and not sent directly. I found a blog that explains that bcc addresses are not sent when using the pickup directory, and instead you can put them in the redo directory. This solved my problem with an easy fix: It is not possible to send a Bcc using System.Net.Mail when specifying the distribution directory (Exchange 2007 / Exchange 2010) in the code

+2
source

I created a test application and ran SmptForDev to capture any emails coming out of my local IIS. I used the code below and it works great. All I really did with your code is order, and everything works fine. I also decompiled System.Net.Mail.SmtpClient to see what it does under the hood, the addresses of the address and Bcc are all in the same collection, if one address sends this well, to assume that they are all there.

 public void SendEmailMessage(string fromAddress, string toAddress, string subject, string body, IEnumerable<string> ccAddress, IEnumerable<string> bccAddress, string filepath) { using (var mailClient = new SmtpClient()) { var mailMessage = new MailMessage(fromAddress, toAddress); foreach (var email in ccAddress) { mailMessage.CC.Add(new MailAddress(email)); } foreach (var email in bccAddress) { mailMessage.Bcc.Add(new MailAddress(email,"Matty Boy")); } mailMessage.Priority = MailPriority.Normal; mailMessage.Subject = subject; if (!string.IsNullOrEmpty(filepath)) { var attachment = new Attachment(filepath, MediaTypeNames.Application.Octet); mailMessage.Attachments.Add(attachment); } var plainTextView = AlternateView.CreateAlternateViewFromString(GetTextonly(body), null, "text/plain"); var htmlView = AlternateView.CreateAlternateViewFromString(body, null, "text/html"); mailMessage.AlternateViews.Add(plainTextView); mailMessage.AlternateViews.Add(htmlView); mailClient.Send(mailMessage); } } 

enter image description here

0
source

As a workaround, you can explicitly send the email address to the BCC address.

After successfully sending the email:

  mailClient.Send(mailMessage); 

Clear the To address collection, then add your BCC address as the To address and resubmit it.

  mailMessage.To.Clear(); // clear the existing To & Cc fields mailMessage.Cc.Clear(); mailMessage.To.Add(new MailAddress(" bcc@address.com ","CopyAddress")); mailClient.Send(mailMessage); 
0
source

All Articles