1
Vote

Sending MailMessage with To Recipient having a DisplayName Generates Erroneous Bcc

description

When I use a simple SmtpClient() client with a To MailAddress that contains a DisplayName, the email address, sans DisplayName, is duplicated as a Bcc. If, however, the To recipient MailAddress does not contain the Bcc.

Simplest reproduction scenario that works I can reproduce this with is:

var client = new SmtpClient();

var message = new MailMessage { From = new MailAddress("a@b.com", "Alex") };
message.To.Add(new MailAddress("c@d.com", "Chris") };
message.Subject = "Test Message";
message.Body = "Hey there!";

client.Send(message);

If I set my <mailSettings> to the loopback on port 25 and use Papercut, it shows up with a Bcc included, that will show "c@d.com". However, if I point it to a live SMTP server or try it with smtp4dev, there is no Bcc in the headers.

Interestingly, it appears to only be the To address that this happens for. If I do not include a DisplayName, the duplication goes away. However, trying it with my ISP host, my hosting provider, or other fake servers, it consistently behaves as expected, with or without a DisplayName. Inspecting the MailMessage at the point of sending, I can confirm that there are no Bcc recipients.

comments