Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi.I cant send email to multiple Recipient. I tried to put a comma for 1st email, but it wont send to it. for example abc@yahoo.com, abc2@yahoo.com
abc2@yahoo.com will get the email but abc@yahoo.com not able to get. Somebody pls help me

Below is my code

What I have tried:

protected void btnUpload_Click(object sender, EventArgs e)
   {
       string Pino = Txtbx_PINo.Text;
       string Bookingno = Txtbx_BookingNo.Text;
       string Email = Txtbx_Email.Text;


       if (Txtbx_Email.Text == null || Txtbx_Email.Text == string.Empty)
       {
           Lbl_Message.Text = "Error. Please Insert Email.";
       }
       else
       {
           string FromName = "BS UPLOAD";
           string FromEmail = "123@gmail.com";
           string UserEmail = Email;
           string UserName = "Username123";
           string Subject = "SHIPPING ADVISE - ";

           System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient();
           smtp.Host = "smtp.gmail.com";
           smtp.Credentials = new System.Net.NetworkCredential("123@gmail.com", "password");
           smtp.EnableSsl = true;
           System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
           msg.From = new System.Net.Mail.MailAddress(FromEmail, FromName);
           msg.To.Add(new System.Net.Mail.MailAddress(UserEmail, UserName));
           msg.IsBodyHtml = true;
           msg.Subject = Subject;
           msg.Body = msg.Body + "Good Day." + "<br><br>";
           msg.Body = msg.Body + "Please find below shipping advise: " + "<br><br>";
           msg.Body = msg.Body + "Thank you." + "<br><br>";
           msg.Body = msg.Body + "Note : Please do not reply this email because it is generated by computer system.";

           try
           {
               smtp.Send(msg);
           }
           catch (FormatException ex)
           {
               Lbl_Message.Text = ("Format Exception: " + ex.Message);
           }
           catch (SmtpException ex)
           {
               Lbl_Message.Text = ("SMTP Exception:  " + ex.Message);
           }
           catch (Exception ex)
           {
               Lbl_Message.Text = ("General Exception:  " + ex.Message);
           }

           Lbl_Message.Text = "Info : This BS is sent to registered user via email.";

       }
   }
Posted
Updated 3-Jun-20 1:15am
Comments
Richard Deeming 3-Jun-20 6:41am    
"This BS is sent to registered user via email"

Unless that's a standard acronym in your customer's business domain, I suggest you look up what "BS" usually stands for before you show that message to your customer. 🤣
Member 14784148 30-Jun-20 23:13pm    
hahaha "BS" stands for Booking Slip

Normally, I'd address the mail to a "noreply" email address on my domain and attach all genuine recipients as BCC addressees, rather than trying to add them as "To" addresses. That way, each recipient does not receive a list of every other customer's email addresses - which is a clear breach of Data Protection / GDPR and could get your company a massive fine.
 
Share this answer
 
Comments
Member 14784148 30-Jun-20 23:23pm    
string[] Multi = ToEmail.Split(','); //spiliting input Email id string with comma(,)
foreach (string Multiemailid in Multi)
{
msg.To.Add(new MailAddress(Multiemailid)); //adding multi reciver's Email Id
}

This works for me, btw thanks for the idea :)
OriginalGriff 1-Jul-20 1:59am    
That is a pretty bad idea, unless you are keeping all those emails internal to the company. If those are private individuals email addresses, that's a big GDPR breach, and that means large fines.
The MailMessage.To property is not a string value; it is actually a collection of email addresses
To add to this collection; you generally would use the Add() method, just like you did for the first recipient.
C#
msg.To.Add(new System.Net.Mail.MailAddress(Email1, Name1));
msg.To.Add(new System.Net.Mail.MailAddress(Email2, Name2));
Reference:
MS Docs: MailAddress Constructor (System.Net.Mail)[^]
 
Share this answer
 
Comments
Member 14784148 30-Jun-20 23:23pm    
string[] Multi = ToEmail.Split(','); //spiliting input Email id string with comma(,)
foreach (string Multiemailid in Multi)
{
msg.To.Add(new MailAddress(Multiemailid)); //adding multi reciver's Email Id
}

This works for me, btw thanks for the idea :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900