I have a thread running in the background that will sleep and pull data from the database when something wakes it up. I am sending the emails using google apps using SmtpClient (code below).
I wanted to know if there is anything i be aware of? I plan to send only one email at a time (a registration or forgot password email). I am a little worried something can happen like an invalid email locking up the thread because i didnt set a timeout or maybe google apps happen to be done and causing the app to blow up. What should i be aware off? I should ask how i should test as well?
var client = new SmtpClient("smtp.gmail.com", 587)
{
Credentials = new NetworkCredential(fromAddr, pass),
EnableSsl = true
};
MailMessage mail = new MailMessage(fromAddr, toAddr, subject, body);
mail.IsBodyHtml = true;
client.Send(mail);
If you’re using IIS. Install SMTP on your server an send all mail to localhost. That way if an email doesn’t go through right away, the SMTP server will queue the email instead of hang your application.
You will need to configure the SMTP server to use gmail as a smarthost. If you need more information about how to configure this, let me know.