Last active
April 6, 2019 04:00
-
-
Save sendgrid-gists/fb86b16be981e203e3d08e67d7863e46 to your computer and use it in GitHub Desktop.
v3 "Hello World" for email, using SendGrid with Python.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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