I am trying to send emails to a single 'To' recipient, and a list of 'Bcc' recipients. The list of Bcc recipients is a list of string, and they are successfully being added to the mailMessage's Bcc collection, but not actually being sent. If I add the same list to the message's 'Cc' collection it works fine. Just not the Bcc collection. The code I'm using is this:
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?
one thing i didn't mention is that the mail is put in a pickup directory rather than sent direct. I found a blog which explains that bcc addresses aren't sent if using a pickup directory, and you can put them in the retry directory instead. This solved my problem with an easy fix: Unable to send Bcc using System.Net.Mail when specifying a Pickup Directory(Exchange 2007/Exchange 2010) in code