2
votes

I have built a email template in MailChimp using their template builder.

I want to send this email to individuals on certain events. For example, if someone forgets their password, I want to send them the 'Forgot Password' template I created in MailChimp.

I've looked at MailChimp's API, but it doesn't seem too friendly to non-bulk email sending. How would I send transactional emails like this, using an HTML template created from MailChimp but using SendGrid for SMTP?

The code would look something like this:

if action == 'forgot_password':
    email = mailchimp.get_template(forgot_password)
    sendgrid.send_mail(user, subject, email, from)
2

2 Answers

1
votes

Not sure what Mailchimp library you're using to get the template. Did some googling and couldn't figure it out, but assuming thet get_template returns the html contents of the email, you could do this:

import sendgrid

s = sendgrid.Sendgrid('username', 'password', secure=True)

if action == 'forgot_password'
  html = mailchimp.get_template(forgot_password)
  message = sendgrid.Message("[email protected]", "subject", text_version_of_template, html)
  message.add_to("[email protected]", "John Doe")
  s.smtp.send(message)

See this question for details about getting a text version of your html.

0
votes

That's exactly what MailChimp's Mandrill transactional mail service is for - it also allows for some levels of template reuse.