How to Set Up Sugar Mail for Local Testing

Testing email notifications is something we find ourselves doing rather often while developing Sugar customizations. Ideally, while doing this, we don’t want to send out emails to recipients not involved in the test. While I usually manage to follow this guideline, recently I failed spectacularly. I was using a local Sugar instance (hosted on vagrant) to develop a scheduled job that would set the value of a field in Meetings module. The email settings in this local instance were pointing to our production email server (first mistake). I used the $bean->save() function in the Meetings module, which triggered a flood of record assignment notifications to all Sugar users who have a meeting assigned to them. This was a somewhat embarrassing result that I did not want to repeat. I started looking into ways to test email notifications without sending out actual emails. Turned out this can be done by using MailCatcher.

The first step is to install MailCatcher on the virtual machine where the local Sugar instance is hosted. The second step is to setup email on Sugar to work with MailCatcher, as shown in the image below.

mail settings to use with MailCatcher

Once you have MailCatcher working on localhost, all outbound emails will show up almost instantly in the MailCatcher tab at http://localhost:1080 (see image below), and will not go any further than that. This makes email testing much less stressful.