Hi,
the System MailMessage class when sending the email via IIS Pickup Directory actually does not include the BCC headers into the email. See this article for details. This is logical, as including Bcc headers into the email to be sent would reveal the BCC addresses to people receiving the email which is not desirable.
Instead the BCC recipients are stored in the "X-Receiver" headers that the IIS server cuts away before actually sending the email.
Parsing the "X-Receiver" headers can be easily done with Rebex Secure Mail. See my code below.
However, please note that apart of the BCC, the X-Receiver headers contains also the standard To and CC addresses. So based on your usage you have to differentiate these apart yourself.
MailMessage mail = new MailMessage();
mail.Load(@"C:\pickupDirectory\13a6b150-4cdc-4238-8beb-4f2966baac9f.eml");
MimeHeader[] xReceivers = mail.Headers.GetAllHeaders("X-Receiver");
List<MailAddress> receivers = new List<MailAddress>();
List<MailAddress> bccRecipients = new List<MailAddress>();
foreach (var xReceiver in xReceivers)
{
var receiver = new MailAddress(xReceiver.Value.ToString());
receivers.Add(receiver);
}
// X-Receiver headers contain all receivers (including To, CC and BCC).
// TODO: based on your usage, filter out the BCC addressees yourself!
// in this simple case let's suppose that To and CC only contains one address and that only one copy of each address occurs in To, CC and BCC
bool toIgnored = false, ccIgnored = false;
foreach (var receiver in receivers)
{
// if X-Receiver is already set in To or CC, ignore the first occurence
if (!toIgnored && mail.To[0].Address == receiver.Address)
{
toIgnored = true;
continue;
}
if (!ccIgnored && mail.CC[0].Address == receiver.Address)
{
ccIgnored = true;
continue;
}
bccRecipients.Add(receiver);
}
foreach (var bccRecipient in bccRecipients)
{
Console.WriteLine("Found possible BCC recipient '{0}'.", bccRecipient);
mail.Bcc.Add(bccRecipient);
}