sending emails using asp.net without crashing the application
<p>I am working on an asp.net application for sending emails. I want to make sure that if something goes wrong, then it logs errors and move to next record. I am using SmtpClient class to send emails. but right now, If some email address is wrong, it just crashes. How to force it to move to next record ?</p>

<p>My code is like this:</p>

<pre><code> var EmailsQueue = context.WC_EmailToolQueue.Where(t =&gt; t.EmailDate == null).ToList();

            foreach (var email in EmailsQueue)
            {
                MailMessage message = new MailMessage();
                message.From = new MailAddress(email.WC_EmailToolTemplates.SenderEmail);
                message.To.Add(new MailAddress(email.Email));
                message.Body = body;
                message.IsBodyHtml = true;
                message.Subject = subject;

                using (SmtpClient smtp = new SmtpClient
                {
                    Host = email.WC_EmailToolTemplates.Host, 
                    Port = email.WC_EmailToolTemplates.Port,  
                    Credentials = new NetworkCredential(email.WC_EmailToolTemplates.SMTPUser, email.WC_EmailToolTemplates.SMTPPass), 
                    EnableSsl = email.WC_EmailToolTemplates.EnableSSL 
                })
                   try
                {
                    smtp.Send(message);
                }
                catch (Exception ex) {

                }
                }
</code></pre>

<p>Regards,
Asif Hameed</p>
