-
Notifications
You must be signed in to change notification settings - Fork 714
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow personalization of the From name and email for each recip…
…ient (#1020) * feat: allow personalization of the From name and email for each recipient
- Loading branch information
Bilal Boussayoud
authored
Oct 25, 2021
1 parent
2e12f1c
commit a97e83a
Showing
6 changed files
with
126 additions
and
14 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
```python | ||
import os | ||
import json | ||
from sendgrid import SendGridAPIClient | ||
from sendgrid.helpers.mail import Mail, Personalization, From, To, Cc, Bcc | ||
|
||
# Note that the domain for all From email addresses must match | ||
message = Mail( | ||
from_email=('from@example.com', 'Example From Name'), | ||
subject='Sending with Twilio SendGrid is Fun', | ||
html_content='<strong>and easy to do anywhere, even with Python</strong>') | ||
|
||
personalization1 = Personalization() | ||
personalization1.add_email(To('test0@example.com', 'Example Name 0')) | ||
personalization1.add_email(Cc('test1@example.com', 'Example Name 1')) | ||
message.add_personalization(personalization1) | ||
|
||
personalization2 = Personalization() | ||
personalization2.add_email(To('test2@example.com', 'Example Name 2')) | ||
personalization2.add_email(Bcc('test3@example.com', 'Example Name 3')) | ||
personalization2.add_email(From('from2@example.com', 'Example From Name 2')) | ||
message.add_personalization(personalization2) | ||
|
||
try: | ||
sendgrid_client = SendGridAPIClient(os.environ.get('SENDGRID_API_KEY')) | ||
response = sendgrid_client.send(message) | ||
print(response.status_code) | ||
print(response.body) | ||
print(response.headers) | ||
except Exception as e: | ||
print(e.message) | ||
``` |