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

前端 未结 6 951
陌清茗
陌清茗 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:27

    This is what worked for me. (recipients is an Array of Strings)

    //Fuse all Receivers
    var allRecipients = String.Join(",", recipients);
    
    //Create new mail
    var mail = new MailMessage(sender, allRecipients, subject, body);
    
    //Create new SmtpClient
    var smtpClient = new SmtpClient(hostname, port);
    
    //Try Sending The mail
    try
    {
        smtpClient.Send(mail);
    }
    catch (Exception ex)
    {
        Log.Error(String.Format("MailAppointment: Could Not Send Mail. Error = {0}",ex), this);
        return false;
    }
    

提交回复
热议问题