Sending emails through MailChimp in Grails

with No Comments

Problem

Need to send Newsletters to users with latest info about service.

Solution

Comparing SendGrid and Mailchimp as two most popular platforms to send emails, we choose Mailchimp as it is used especially for newsletters sending – not just mass email send.

After some research with mailchimp grails plugin we decide to write our own Service to use latest API with endpoints we need in the project.

Things we wanted to achive:

    1. Possibility to subscribe user with definition of his gender, age, city, country
    2. Possibility to choose ours predefined template with dynamic content
    3. Possibility to send newsletter based on gender, age, city, country
    4. Possibility to send newsletter to selected email list, which should be stored for SalesMan so that he can update/reuse it

We’ve added to Config.groovy similar fields that used in grails mailchimp plugin:

gchimp.apiUrl = 'https://us5.api.mailchimp.com/1.3/'
gchimp.apiKey = 'sgsgsg34t2345sfgsgf-us5'
gchimp.defaultListId = 'sgsgfsdg32'
gchimp.salesListId = 'afssf2334'

To cover first two options we’ve updated login UI for user with subscribe to newsletter tick and other fields and created CRUD for Template creation. So, we always send template we want to use to Mailchimp in HTML format – never use theirs.

For all other needs we created Service to comunicate with Mailchimp

I won’t go in details through this service, but maybe somebody find there useful things

Leave a Reply