locked
How to get the failed email addresses? RRS feed

  • Question

  • using System.Net.Mail;

    public void SendMailNow(string from, string to, string title, string content)  
            {  
                SmtpClient smtp = new SmtpClient(Host);  
                smtp.DeliveryMethod = SmtpDeliveryMethod.Network;  
                MailMessage msg = new MailMessage(from, to, title, content);  
                msg.BodyEncoding = Encoding.GetEncoding(950);               
    msg.SubjectEncoding = Encoding.GetEncoding(950); //950 - traditional chinese  
                smtp.Send(msg);  
            } 
     I use the above code to send email. How can I get the failed email addresses?
    Thursday, October 2, 2008 8:47 AM

Answers

  • public void SendMailNow(string from, string to, string title, string content)     
    {    
         List<string> FailedAddresses = new List<string>();  
        try 
        {     
                SmtpClient smtp = new SmtpClient(Host);     
                smtp.DeliveryMethod = SmtpDeliveryMethod.Network;     
                MailMessage msg = new MailMessage(from, to, title, content);     
                msg.BodyEncoding = Encoding.GetEncoding(950);                  
           msg.SubjectEncoding = Encoding.GetEncoding(950);     
                smtp.Send(msg);     
        }  
              catch(SmtpFailedRecipientsException ex)  
        {  
            FailedAddresses.Add(to);  
            MessageBox.Show(ex.Message);  
        }  
            }   
    Tommy2008 said:

    using System.Net.Mail;

    public void SendMailNow(string from, string to, string title, string content)  
            {  
                SmtpClient smtp = new SmtpClient(Host);  
                smtp.DeliveryMethod = SmtpDeliveryMethod.Network;  
                MailMessage msg = new MailMessage(from, to, title, content);  
                msg.BodyEncoding = Encoding.GetEncoding(950);               
    msg.SubjectEncoding = Encoding.GetEncoding(950); //950 - traditional chinese  
                smtp.Send(msg);  
            } 
     I use the above code to send email. How can I get the failed email addresses?



    Try this code. You will have all failed addresses in the FailedAddresses List:


     
    Thursday, October 2, 2008 6:46 PM