0

I am trying WebMail.Send() to send mail to multiple email ids. The MSDN library page clearly specifies that multiple email ids should be separated by semicolon(;). However when I try to send mails to multiple ids, I get FormatException with Message that says "An invalid character was found in the mail header: ';'. However if I send mail to single receipent, the mail gets delivered properly.

So, how do I send mails to multiple receipents using WebMail.Send()? Perhaps I am missing something very obvious.

Edit: Here is the code that I am using.

string [] selectedUserIds = GetEmailIds();
string to = string.Join(";", selectedUserIds);
WebMail.Send(to: to, subject: subject, body: message, cc: cc, filesToAttach:   attachments, isBodyHtml:true);
ckittel
  • 6,478
  • 3
  • 41
  • 71
Jatin
  • 4,023
  • 10
  • 60
  • 107

2 Answers2

1

I think it is a documentation error. The delimiter works for ,. This is the standard delimiter for email addresses.

See for the System.Net.Mail namespace: http://msdn.microsoft.com/en-us/library/14k9fb7t.aspx - see the last comment.

Valamas
  • 24,169
  • 25
  • 107
  • 177
  • There are no multiple from addresses. Its a single from address that I have configured in Web.Config. For code please see my question, I have edited it to include the relevant code. – Jatin Aug 11 '11 at 00:47
  • I wonder if you have a rogue ; at the start or end of the variable `to`. – Valamas Aug 11 '11 at 00:56
  • Valamas, the to field is properly formatted and contains entries like this "abc@domain.com;xyz@domain.com". I checked that in debugger. There is no other semicolon(;) anywhere in variable to. – Jatin Aug 11 '11 at 01:43
  • Valamas, I would never have imagined that issue. Thanks to you. I can now send mails to multiple receipents. – Jatin Aug 11 '11 at 02:20
0

The System.Net.Mail-related classes all use , to seperate addresses in the To, Cc, and Bcc fields. I suggest you change your code to look like:

string to = string.Join(",", selectedUserIds);
ckittel
  • 6,478
  • 3
  • 41
  • 71