I have multiple email recipients stored in SQL Server. When I click send in the webpage it should send email to all recipients. I have separated emails using ;
.
Following is the single recipient code.
MailMessage Msg = new MailMessage(); MailAddress fromMail = new MailAddress(fromEmail); Msg.From = fromMail; Msg.To.Add(new MailAddress(toEmail)); if (ccEmail != "" && bccEmail != "") { Msg.CC.Add(new MailAddress(ccEmail)); Msg.Bcc.Add(new MailAddress(bccEmail)); } SmtpClient a = new SmtpClient("smtp server name"); a.Send(Msg); sreader.Dispose();
Click the compose box, after composing your message, click on BCC and add all your recipients. This will send the emails to the recipients keeping email addresses hidden from each other.
In the preceding class file I used a foreach loop to add the multiple recipient's Email Ids but before that we are using the comma (,) separated input email ids from user in one string "Tomail" then we are splitting the input sting with (,) commas and added to one string array named "Multi" then using a foreach loop we ...
If you want to use smtplib to send email to multiple recipients, use email. Message. add_header('To', eachRecipientAsString) to add them, and then when you invoke the sendmail method, use email. Message.
Easy!
Just split the incoming address list on the ";" character, and add them to the mail message:
foreach (var address in addresses.Split(new [] {";"}, StringSplitOptions.RemoveEmptyEntries)) { mailMessage.To.Add(address); }
In this example, addresses
contains "[email protected];[email protected]
".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With