6

I have been reading a lot on the Internet to know how I can use Python to send emails using mailchimp API. It seems that the website is so complected and doesn't have any example.

Please, could you guide me to any example including a Python use?

What I tried so far:

  • I installed the library from pip using: pip install mailchimp;

  • I have created the campain;

  • I have created the lists;

But yet, I couldn't know how to send the emails programmatically.

Uncle Ben Ben
  • 482
  • 3
  • 11
Marco Dinatsoli
  • 10,322
  • 37
  • 139
  • 253
  • What about this? https://github.com/mailchimp/mcapi2-python-examples – mrcrgl Apr 21 '15 at 12:19
  • @mrcrgl I have already checked that link and the read me of it. there is no code there to send email, you can check – Marco Dinatsoli Apr 21 '15 at 12:21
  • If you just want to send email and not do mailing lists, Mandrill is a spin off company from Mailchimp: http://mandrill.com/ - they give you SMTP server credentials and after that you can follow in Python email sending tutorial using those credentials. – Mikko Ohtamaa Apr 21 '15 at 12:30
  • @MikkoOhtamaa may you show me the link for the tutorial please? – Marco Dinatsoli Apr 21 '15 at 12:42
  • Google is your friend: http://stackoverflow.com/questions/882712/sending-html-email-using-python - just configure `smtplib.SMTP()` with your external SMTP server credentials. – Mikko Ohtamaa Apr 21 '15 at 12:55

1 Answers1

14

If you want to trigger a campaign see:

https://apidocs.mailchimp.com/api/2.0/campaigns/send.php

The typical module mailchimp at pypi supports it as followed.

from mailchimp import Mailchimp
mailchimp = Mailchimp(api_key)
mailchimp.campaigns.send(campaign_id)

Sourcecode at: https://bitbucket.org/mailchimp/mailchimp-api-python/src/32ed2394d6b49d7551089484221fa3ee019bee37/mailchimp.py?at=master

Hope it helps.

Cheers, mrcrgl

mrcrgl
  • 640
  • 4
  • 11
  • That is helpful really, but how can i got the `api_key`? plus, i have already added a campaign but i didn't receive any `campaing-id` – Marco Dinatsoli Apr 21 '15 at 12:35
  • do you mean by `api_key` the `client_secret` key in the dashbaord when you create an app? or the `client_id` ? – Marco Dinatsoli Apr 21 '15 at 12:37
  • I imported `mailchimp` and when I tried your first code, i got `NameError: name 'Mailchimp' is not defined` – Marco Dinatsoli Apr 21 '15 at 12:39
  • You need to import it `from mailchimp import Mailchimp`. I'm not a customer of mailchimp, so, please research and try yourself. I'll paste the current code of mailchimp client sdk into my answer, there you see the methods – mrcrgl Apr 21 '15 at 13:37