Obtain Excepcion when a mail does not reach its recipient by a badly written recipient or that does not exist

0

I have this code

public void SendEMail(string recipient, string subject, string message)
        {
            try
            {
                //Intialise Parameters  
                SmtpClient client = new SmtpClient(clientAddress);

                System.Net.NetworkCredential credentials = new System.Net.NetworkCredential(smtpUser, netPassword);


                client.UseDefaultCredentials = false;
                client.Credentials = credentials;

                MailMessage mail = new MailMessage(
                                 senderAddress.Trim(), recipient.Trim());

                mail.From = new MailAddress(senderAddress, "ANONIMOS S,A");
                mail.Subject = subject;
                mail.Body = message;
                mail.IsBodyHtml = true;
                //create Alrternative HTML view
                AlternateView htmlView = AlternateView.CreateAlternateViewFromString(message, null, "text/html");

                //Add Image
                LinkedResource theEmailImage = new LinkedResource(HttpContext.Current.Server.MapPath("~/Content/" + "images/enacal.png"));
                theEmailImage.ContentId = "myImageID";

                //Add the Image to the Alternate view
                htmlView.LinkedResources.Add(theEmailImage);

                //Add view to the Email Message
                mail.AlternateViews.Add(htmlView);


                client.Send(mail);
            }
            catch (System.Net.Mail.SmtpFailedRecipientException ex)
            {

                throw ex;
            }

        }

I want to get an exception, when the email is not sent to the recipient.

I have read that the SMTP protocol only takes care of sending the mail and does not take care of receiving an answer.

What solution exists to generate a status of the response of the shipment? I would appreciate it !!!

    
asked by Assiel Nahum Reyes Umaña 09.04.2018 в 22:09
source

0 answers