-
Notifications
You must be signed in to change notification settings - Fork 728
Closed
Labels
status: work in progressTwilio or the community is in the process of implementingTwilio or the community is in the process of implementingtype: twilio enhancementfeature request on Twilio's roadmapfeature request on Twilio's roadmap
Description
Issue Summary
Is it possible to use transactional templates and send to multiple recipients that have their own dynamic data? If it is possible it would be great if an example could be added to the documentation.
I'm doing this currently by creating a message for each recipient individually, and then sending individually. What I'd like to do is a cross between the sending multiple emails to multiple recipients example and the transactional templates example.
This is my current solution:
import csv
from sendgrid import SendGridAPIClient
from sendgrid.helpers.mail import Mail, To
key = MY_KEY
sg = SendGridAPIClient(key)
with open("test.csv") as csv_file:
recipients = [
{k: v for k, v in row.items()}
for row in csv.DictReader(csv_file, skipinitialspace=True)
]
for recipient in recipients:
message = Mail(from_email="from_email@example.com", to_emails=recipient["email"],)
message.dynamic_template_data = {
"name": recipient["name"],
"dummy": recipient["dummy"],
}
message.template_id = MY_TEMPLATE_ID
try:
response = sg.send(message=message)
print(response.status_code)
print(response.body)
print(response.headers)
except Exception as e:
print(e)
I'd like to be able to submit this all as one job though.
Metadata
Metadata
Assignees
Labels
status: work in progressTwilio or the community is in the process of implementingTwilio or the community is in the process of implementingtype: twilio enhancementfeature request on Twilio's roadmapfeature request on Twilio's roadmap