2

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)
David542
  • 104,438
  • 178
  • 489
  • 842

2 Answers2

1

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("from@mydomain.com", "subject", text_version_of_template, html)
  message.add_to("someone@example.com", "John Doe")
  s.smtp.send(message)

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

Community
  • 1
  • 1
Swift
  • 13,118
  • 5
  • 56
  • 80
0

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

jesse
  • 470
  • 2
  • 6