Email Marketing for your Rails App Made Easy With Mailchimp
So you’ve got an awesome web application up and running. You want to keep your users engaged. You could try to handle collecting emails, writing your own newsletters, managing the list, keeping content fresh, tracking who read your messages, and so on (and so on) — all within your own app; however, there’s a better way. We recommend using Mailchimp. It’s actually very simple to integrate Mailchimp into your own Ruby on Rails application. Quick. Easy. DRY. Just the way we like it.
At Highgroove, we’re notorious for not wanting to re-invent the wheel. We LOVE using plugins, open-source libraries, ruby gems, and other external integrations in our apps. Mailchimp.com is one of those external services we regularly rely on.
A fairly common scenario is to collect user emails and send them a subscriber newsletter. We need all the basics: collect the email itself, ensure the email is real, send the actual newsletter on a certain schedule, and allow users to opt-out or change their email profile settings.
The first step to completing this online subscriber newsletter is to signup for Mailchimp.com. Once that is done, provide your API Key to us.
The second step is to create a List within Mailchimp. This List could be called “My Sites Newsletter”, for example.
Now that we’ve taken care of all the setup of Mailchimp, the next couple of steps will show you just how amazing Mailchimp.com and Gibbon really are:
On a basic level, all we need in the Rails application’s code is an HTML form that collects an email address and some code within a controller method to save the submitted email address to Mailchimp. We do this in two steps:
First, create your form (this example is a HAML template):
Two, in your controller, add a line like this:
Once you’ve done the above, your Rails app is fully integrated with Mailchimp! The content, frequency, and other settings that have to do with your newsletter are all controlled in Mailchimp’s very simple interface.
The only question you’ll have left at this point is “What cool feature can we add next?”