Basic Usage of sendGrid API using python

import os
from sendgrid import SendGridAPIClient
from sendgrid.helpers.mail import Mail

print('Enter Subject for message')
subject = input()

message = Mail(
    from_email='[email protected]',
    to_emails='[email protected]',
    subject=subject,
    html_content='<strong>This message is sent from sendGrid using 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)

Built With

Share this project:

Updates

Submission history