.Net System.Mail.Message adding multiple “To” addresses

前端 未结 8 1369
悲&欢浪女
悲&欢浪女 2020-12-30 18:56

EDIT: This question is pointless, except as an exercise in red herrings. The issue turned out to be a combination of my idiocy (NO ONE was being emailed as the hos

8条回答
  •  傲寒
    傲寒 (楼主)
    2020-12-30 19:38

    private string FormatMultipleEmailAddresses(string emailAddresses)
        {
          var delimiters = new[] { ',', ';' };
    
          var addresses = emailAddresses.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);
    
          return string.Join(",", addresses);
        }
    

    Now you can use it like

    var mailMessage = new MailMessage();
    mailMessage.To.Add(FormatMultipleEmailAddresses("test@gmail.com;john@rediff.com,prashant@mail.com"));
    

提交回复
热议问题