c#, asp.net send emails

Hi,

I have the below code using to send emails.

What I want to check is that if the email has been sent and delivered or if not delivered.

For example wrong email address or something like that

  var smtp = new System.Net.Mail.SmtpClient();

            {
                smtp.Host = "smtp.live.com";
                smtp.Port = 600;
                smtp.EnableSsl = true;
                smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
                smtp.Credentials = new NetworkCredential(fromAddress.Address, fromPassword);
                smtp.Timeout = 20000;


            }
            using (var message = new MailMessage(fromAddress, toAddress)
            {
                Subject = subject,
                Body = body,
                IsBodyHtml = true,
            })

Open in new window


Please help

Thanks

R8VI
R8VIAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Monica PSoftware DeveloperCommented:
Hi

The process what i have done is

I have used try catch block..In catch block if there is error i have created log to check the status of mail process.

If this suits for your need make use of this logic..
0
R8VIAuthor Commented:
Hi

This is what I have but the code doesn't go into the catch

  var smtp = new System.Net.Mail.SmtpClient();

        {
            smtp.Host = "smtp.live.com";
            smtp.Port = 587;
            smtp.EnableSsl = true;
            smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
            smtp.Credentials = new NetworkCredential(fromAddress.Address, fromPassword);
            smtp.Timeout = 20000;


        }
        using (var message = new MailMessage(fromAddress, toAddress)
        {
            Subject = subject,
            Body = body,
            IsBodyHtml = true,
        })
        {
            try
            {
                smtp.Send(message);
            }
            catch (Exception ex)
            {
                string x = ex.ToString();
            }
        }

Open in new window

0
Monica PSoftware DeveloperCommented:
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
R8VIAuthor Commented:
HI,

I have added the following to the code, but when debugging the code does not go into the catch block please help

 using (var message = new MailMessage(fromAddress, toAddress)
        {
            Subject = subject,
            Body = body,
            IsBodyHtml = true,
        })
            try
            {
                smtp.Send(message);
            }
            catch (SmtpFailedRecipientsException ex)
            {
                foreach (var innerEx in ex.InnerExceptions)
                {
                    var status = innerEx.StatusCode;
                }
            }

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.