Friday, 5 April 2013

Using SendGrid to send emails (with TM email logging and offline detection)

Roman just opened up the Emails are not sent consistently when they should be sent issue which I believe is caused by the fact that his test box went offline in the middle of his QA tests.

At the moment, before TeamMentor sends an email there is a check to see if we current server is offline (as shown below, the offline check is done after adding the email message to a temp Sent_EmailMessages variable, which is the one used in the TBot's View Email Messages page):

image

This offlineMode Extension Method will check if:

  • the SMTP values are set, and 
  • the current server is offline.


image

The offline checks is done using using the MiscUtils.online method,  which makes a HEAD request to Google:

image

This means that if the server is offline, there are no emails sent, but they are stored in a temp variable (which will help debugging).


Note that doing this online check using HEAD is faster than waiting for the SMTP method to thrown a timeout exception.

Improvement ideas:


For the next version of TM here are a couple improvements that I think could be done:
  • TBot thread responsible for sending emails (and handle retrying email sending for cases like this)
  • Store on file system the emails that failed to be sent
  • Have a config setting that defines that the server SHOULD be online and raise an admin error when non-expected offline modes occur (the offline mode is really there for QA testing and cases where the SMTP server is not set)
  • Improve Email error flag to differentiate the offlineMode created by the lack of SMTP config values and a real offline scenario
SendGrid on TeamMentor

We have been using SendGrid to send emails from TeamMentor (see here for more details on the TeamMentor SMTP requirements) and apart from its email sending capabilities, the usage graphs and reporting are pretty cool:

Dashboard:

image

Global Stats:

image

Email Activity:

image

Email Bounces:

image

Email blocks:

image

Invalid emails:

image

Unsubscribes:

image

SendGrid account type used:

At the moment we are using the Free package,

image

but I expect that we will soon be upgrading to a Lite or Bronze package:

image

As you can see SendGrid it is working ok for us, and there are only a couple things that I need to figure out how to tweak it (Update, see below for how I addressed these issues):
  • Disable the tracking of email clicks (since that replaces TeamMentor links with SendGrid redirects)
  • Create a user that only has ‘send email’ privileges
  • Change or improve the ‘unsubscribe to email alerts’ link (since that could have a couple user un-expected side effects, for example users not being able to get password resets)
------------------------------------------------------------------------------------------------------------
Update 1: I just noticed that SendGrid now supports multiple accounts, which I think it is new since this is something that I wanted for deployed servers (the original SendGrid documentation and examples use the main SendGrid account for SMTP access, which of course is not a good idea (since it forces us to put the main SendGrid account details on production servers))

image

Update 2: after digging a bit on the SendGrid site I found the place to disable click tracking, open tracking and email unsubscribe page (which was one of my open items to solve)

This is done by openning the Settings wizard on the Developers page:

image

And chose No, I do not want Click Tracking

image

Click Next, and select No, I do not want Open Tracking

image

Click next and chose No, I do not want Unsubscribe Management

image

And that's it. SendGrid should be working exactly how we want it to :)
Post a Comment