Click here to Skip to main content
15,909,953 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear Friends,

I am facing a issue while sending mail to multiple receiptant,
if any one of email id failed or is wrong, none or rest of the mails are not getting delivered.

sample code.

C#
MailMessage m = new MailMessage();
           SmtpClient sc = new SmtpClient();
           m.From = new MailAddress("a@dot.com", "Vijay Kumar");
           string sMailIds = "a@dot.com,b@dot.com,b@dot.com";
           if (sMailIds.Trim() != string.Empty)
           {
               string[] mailid = sMailIds.Split(',');
               try
               {
                   foreach (string mail in mailid)
                   {
                      m.To.Add(new MailAddress(mail, "Test"));
                   }
                   m.Subject = "Test";
                   m.Body = "test";
                   m.IsBodyHtml = true;
                   sc.Host = "mail.adityabirla.com";
                   sc.Credentials = new System.Net.NetworkCredential("abc@dot.com", "xyz");
                   sc.Send(m);
               }
               catch (Exception ex)
               {
               }
           }
Posted
Comments
OriginalGriff 2-Mar-13 7:43am    
Don't edit solutions to add comments - use the reply feature instead.
Read what I said: Add a second try catch block around the MailAddress create.
Singh Vijay Kumar 4-Mar-13 3:04am    
Sorry but you are not getting what i am trying to Say.

Thanks Leave It.

1 solution

I assume that what is happening is that the creation of the MailAddress is throwing an exception - but you can't tell because you are swallowing the exception and ignoring it. Never do that! Log it somewhere so that when you get a problem like this you can actually tell what the heck happened...

So, change your catch block to report a problem, or log it, and look at what the exception is, then probably you need to either check the mail variable for validity before you try to create it as a MailAddress, or add a try-catch block around the actual creation of each MailAdress - then report which one is faulty so you can correct in in your database.


That's just a sample dude, i'll take all exception handling, i am just asking a solution that how to take care failure of rest mail message if any one of them fails.

Just want to ignore failed id and rest ids should receive the mail, but its not happing actually.
 
Share this answer
 
v3

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