I am trying to use the System.Net.Mail.MailMessage
class in C# to create an email that is sent to a list of email addresses all via BCC
. I do not want to include a TO
address, but it seems that I must because I get an exception if I use an empty string for the TO
address in the MailMessage
constructor. The error states:
ArgumentException
The parameter 'addresses' cannot be an empty string.
Parameter name: addresses
Surely it is possible to send an email using only BCC
as this is not a limitation of SMTP.
Is there a way around this?
I think you were trying to do something like :
That's why you were seeing the error message.
Instead, try something like this:
Must have a to address. It has been this way since the original sendmail an implementations in the 80s and all SMTP mailers, I know of, have the same requirement. You can just use a dummy address for to.
I think if you comment out the whole
emailMessage.To.Add(sendTo);
line , it will send the email withTo
field empty.You can use a temporary fake address then remove it just after:
You have to include a TO address. Just send it to a "junk" email address that you don't mind getting mail on.
Do the same thing you do for internal mail blasts where you don't want people to reply-to-all all the time.
Send it to yourself (or a dummy account), then add your BCC list.