locked
how to send message to more than one email at the same time RRS feed

  • Question

  • User-1634604574 posted

    how to send message to more than one email at the same time without using entity frame work

    Friday, August 30, 2019 9:19 AM

All replies

  • User-821857111 posted

    Which part are you having difficulty with? Sending multiple emails? Getting data from a database without using EF? Sending one message to multiple recipients?

    Friday, August 30, 2019 9:57 AM
  • User-1634604574 posted

    Sending one message to multiple recipients

    Friday, August 30, 2019 10:35 AM
  • User-171003712 posted

    You can use BCC and CC or you can add multiple email with semicolon ";" 

    or let me know the code 

    here is some sample.

    System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
    mail.To.Add(ToEmail);
    foreach (var address in BCCEmail.Split(new[] { ";" }, StringSplitOptions.RemoveEmptyEntries))
    {
    mail.Bcc.Add(address);
    }
    mail.From = new MailAddress(System.Configuration.ConfigurationManager.AppSettings["EmailSenderID"].ToString());
    mail.Subject = Subject;
    mail.Body = Body;
    mail.Priority = MailPriority.High;
    mail.IsBodyHtml = true;
    SmtpClient smtp = new SmtpClient();
    smtp.Port = 587;
    smtp.Host = "smtp.gmail.com";
    smtp.Timeout = Int32.MaxValue;
    smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
    smtp.Credentials = new System.Net.NetworkCredential(System.Configuration.ConfigurationManager.AppSettings["EmailSenderID"], System.Configuration.ConfigurationManager.AppSettings["EmailSenderPassword"]);
    smtp.EnableSsl = true;
    smtp.Send(mail);



    Friday, August 30, 2019 10:42 AM
  • User1724605321 posted

    Hi zhyanadil.it ,

    If using MailMessage  , you can add recipients like :

    MailMessage msg = new MailMessage();
    msg.Body = ....;
    msg.To.Add(...);
    msg.To.Add(...);
    
    SmtpClient smtp = new SmtpClient();
    smtp.Send(msg);

    Or use inline function :

    msg.To.Add("abc@gmail.com,xyz@gmail.com")

    Best Regards,

    Nan Yu

    Monday, September 2, 2019 3:01 AM