2) Integrate MailChimp with your Mandrill account (in order to import MailChimp Templates)
3) Import your MailChimp Templates into Mandrill
Once these steps have been completed, you’ll no longer see “via " when emails are sent and it should reduce the likelihood of your emails ending up in a spam folder. Additionally, you'll be able to create beautiful templates very easily in MailChimp and have them available within Mandrill.
Devise has several methods it uses by default for email-related purposes. If you review the devise gem’s mailer, you can see their conventions:
So in order to override the default mailer, you must first specify your mailer class (and an email address) in the devise configuration file:
Now you need to override Devise’s Mailer with your own methods:
After doing this, you need to add some mailer code. Now, for the purposes of this post, I decided to use an existing template that I pulled from MailChimp into Mandrill. That means I had to add some variables into the template. The following is an example Forgot Password template:
As you can see, I used a marker or placeholder for the content to be substituted:
The password reset code is below. The key point to notice is that the options hash contains the name of the template as well as
global\_merge\_vars, an array of hashes that contains the name of the variable to replace
(password\_reset\_link) and the replacement content (“http://www.example.com/users/….). The options hash is sent to the
mandrill\_send method which then calls
This last piece is just making sure the configuration file is set up for Mandrill:
With all that done, you should be able to send email via Mandrill leveraging MailChimp and overriding Devise’s default mailer!