using (MailMessage message = new MailMessage()) { MailAddress from = new MailAddress("Sender@domain.com", "Customer Information"); message.From = from; to = ChangeSeprators(to); //to split input string. e.g. abc@domain.com;def@domain.com if (!string.IsNullOrEmpty(to)) { message.To.Add(to); } cc = ChangeSeprators(cc);//to split input string. e.g. abc@domain.com;def@domain.com if(!string.IsNullOrEmpty(cc)) message.CC.Add(cc); message.Subject = emailSubject; message.Body = emailBody; message.Attachments.Add(new Attachment(attachment)); message.BodyEncoding = Encoding.UTF8; message.IsBodyHtml = true; SmtpClient smtpClient = new SmtpClient(server); try { smtpClient.Send(message); } catch (Exception ex) { throw new Exception(ex.Message); } }
ChangeSeprators
to
cc
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)