sendgrid/sendgrid-python

Sending multiple emails with different HTML content in batch

myslak71 opened this issue · 2 comments

Issue Summary

Trying to send multiple emails each with different HTML content without using dynamic templates. Found this java example using substitutions https://stackoverflow.com/a/35040850/10675271 but couldn't recreate it with Python SDK is tha possible?

The snippet I'm using:

p1 = Personalization()
p1.add_substitution(Substitution("%content%", {**data, "full_name": "name1"}))
p2 = Personalization()
p2.add_substitution(Substitution("%content%", {**data, "full_name": "name2"}))
to_emails = [
    To(email="mail1@gmail.com", p=p1),
    To(email="mail2@gmail.com.com", p=p2),
]
mail = Mail(
    from_email="platform@alocai.com",
    to_emails=to_emails,
    is_multiple=True,
    html_content="%content%",
    subject="Subject!!",
)

I think you'll need to flatten the content of your substitution to a string, similar to the payload being used here: https://docs.sendgrid.com/ui/sending-email/substitution-and-section-tags#simple-name-substitution

Closing due to inactivity. Please re-open this issue or open a new GitHub issue if you still need help.