Dec 8, 2018

Python Sparkpost sample

How to send emails from Python using Sparkpost module


In this tutorial, we will see how to send emails using Sparkpost.

First you need to register with Sparkpost and get your API key, so that you can use this key in sending e-mails.

The advantage/beauty of using sparkpost module is

  • You can send thousands of emails even in the free-tier.
  • You can send attachments & you can use html.
  • You can schedule the emails for future date & time.
  • You can also delete the future emails if not required.
  • It has lot more flexible features than inbuilt smtplib.
  • You can check the delivery status of your emails in Sparkpost dashboard (once you login, you can able to see this)
  • Python API is very simple to use, they also support their APIs in multiple languages.


from sparkpost import SparkPost

emails_to_send = ['test@gmail.com']
sp = SparkPost('XXXXXXXXXXXXXXXXXXXXXXXX') #Key

response = sp.transmissions.send(
          recipients=emails_to_send,
          html='',
          from_email='noreply@test.com',
          subject='test'
)
print(response)