Sendgrid allows to specify unique arguments when sending emails. These can be used for the event webhook integration to identify emails doc.
I have an existing code piece in django that uses django.core.mail.EmailMultiAlternatives
to send emails via SendGrid. I'd like to specify the above mentioned unique arguments if possible. So far I was trying to use the custom_args
field
email.custom_args = {'test_arg': 'value'}
but that didn't seem to work. I saw that there's a django-sendgrid module, but if possible I'd prefer not having to re-write the existing code base.
i don't use the SendGrid, but looks like the Unique Arguments
is email headers
, and by the doc: emailmessage, you can add headers
for example:
from django.core.mail import EmailMultiAlternatives
subject, from_email, to = 'hello', '[email protected]', '[email protected]'
text_content = 'This is an important message.'
msg = EmailMultiAlternatives(
subject,
text_content,
from_email,
[to], headers={"customerAccountNumber": "55555", },
)
msg.send()