Skip to content

Instantly share code, notes, and snippets.

@sendgrid-gists
Last active April 6, 2019 04:00
Show Gist options
  • Save sendgrid-gists/fb86b16be981e203e3d08e67d7863e46 to your computer and use it in GitHub Desktop.
Save sendgrid-gists/fb86b16be981e203e3d08e67d7863e46 to your computer and use it in GitHub Desktop.
v3 "Hello World" for email, using SendGrid with Python.
# using SendGrid's Python Library
# https://github.com/sendgrid/sendgrid-python
import os
from sendgrid import SendGridAPIClient
from sendgrid.helpers.mail import Mail
message = Mail(
from_email='[email protected]',
to_emails='[email protected]',
subject='Sending with Twilio SendGrid is Fun',
html_content='<strong>and easy to do anywhere, even with Python</strong>')
try:
sg = SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
response = sg.send(message)
print(response.status_code)
print(response.body)
print(response.headers)
except Exception as e:
print(e.message)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment