sklarsa / django-sendgrid-v5

An implementation of Django's EmailBackend compatible with sendgrid-python v5+
MIT License
318 stars 54 forks source link

Sending different dynamic_template_data per each recipient #112

Closed Janekk closed 2 years ago

Janekk commented 2 years ago

Hello,

is it possible to use Sendgrid personalizations in a way that allows sending dynamic template data per each recipient? E.g. with Sendgrid API you can do the following:

            message = Mail(from_email=From(EMAIL_SENDER_ADDRESS, EMAIL_SENDER_NAME))
            personalization = Personalization()
            personalization.add_to(To(to_email))
            personalization.dynamic_template_data = message_context
            message.add_personalization(personalization)
            message.template_id = notification_config.sendgrid_template_id
            sg_client.send(message=message)

that way we can add different personalization per each recipient and send different dynamic_template_data to each

sklarsa commented 2 years ago

Sure! You can create an EmailMessage object for each user and modify each object with the dynamic template data accordingly. See the dynamic template example in the readme for an example of how to do this.