- install dependencies
pip install sendgrid- Create an api key in sendgrid
- Plug it in on line 13
- Run the script
python main.py| #!/usr/bin/env python | |
| # * coding: utf8 * | |
| """ | |
| main.py - A script that send an email with sendgrid | |
| """ | |
| from sendgrid import SendGridAPIClient | |
| from sendgrid.helpers.mail import Mail | |
| from_address = 'no-reply@utah.gov' | |
| to = ['dford@utah.gov', 'pfunk@utah.gov'] | |
| api_key = 'SG....' | |
| message = Mail(from_email=from_address, to_emails=to, subject='email is working', html_content='<strong>hi</strong>') | |
| try: | |
| client = SendGridAPIClient(api_key) | |
| response = client.send(message) | |
| print(response.status_code, response.body, response.headers) | |
| except Exception as e: | |
| print(f'Error sending email with SendGrid: {e}') |