Search code examples
c#.netsystem.net.mailmailmessage

Multiple address in MailAddress constructor


i was trying to add multiple to address like this.

MailAddress mailAddressTo = new MailAddress("[email protected];[email protected]","Vetrivelmp");

but throws error like

An invalid character was found in the mail header: ';'

Solution

  • You cannot use the MailAddress constructor for specifying multiple receipts, but you can to use the MailMessage object as showed below.

    Using the MailMessage (not MailAddress) constructor:

    var msg = new MailMessage("[email protected]", "[email protected], [email protected]");
    

    another way is:

    MailMessage mail = new MailMessage();
    mail.To.Add("[email protected],[email protected],[email protected]");
    

    another way is:

    MailMessage msg = new MailMessage();
    msg.To.Add("[email protected]");
    msg.To.Add("[email protected]");
    msg.To.Add("[email protected]");
    msg.To.Add("[email protected]");