Unable to send an email to multiple addresses/recipients using C#

前端 未结 6 949
陌清茗
陌清茗 2020-12-01 11:09

I am using the below code, and it only sends one email - I have to send the email to multiple addresses.

For getting more than one email I use:

strin         


        
6条回答
  •  無奈伤痛
    2020-12-01 11:41

    To send to multiple recipients I set up my recipient string with a comma as my separator.

    string recipient = "foo@bar.com,foo2@bar.com,foo3@bar.com";
    

    Then to add the recipients to the MailMessage object:

    string[] emailTo = recipient.Split(',');
    for (int i = 0; i < emailTo.GetLength(0); i++)
        mailMessageObject.To.Add(emailTo[i]);
    

提交回复
热议问题