Bootstrap FreeKB - SendGrid - Sending email to multiple recipients using Python
SendGrid - Sending email to multiple recipients using Python

Updated:   |  SendGrid articles

This assume you are already familiar with sending a basic sendgrid email template using Python. If not, check out my article Sending email using Python.

Here is an example of how to send to multple recipients. This is just the boilerplate code, no error handling, just to focus on the most important markup.

#!/usr/bin/python3
import base64
import os
from sendgrid import SendGridAPIClient
from sendgrid.helpers.mail import (Mail, To)

message = Mail(
    from_email='from@example.com',
    to_emails=[To('john.doe@example.com'), To('jane.doe@example.com')]
    subject='hey',
    html_content='Hello <strong>World</strong>')

sg = SendGridAPIClient('YOUR API KEY')
response = sg.send(message)

print(f"response.status_code = {response.status_code}")
print(f"response.body        = {response.body}")
print(f"response.headers     = {response.headers}")

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter e86051 in the box below so that we can be sure you are a human.