7
ok, So finally I found the solution.
Finally, I figured out how to send unique_args to SendGrid with Django EmailMultiAlternatives. Here is my working solution:
from django.core.mail import EmailMultiAlternatives
from smtpapi import SMTPAPIHeader
header = SMTPAPIHeader()
header.set_unique_args({'customerAccountNumber': '12345','activationAttempt': '1'})
subject, from_email, to = 'hello', 'EXAMPLE@FROM.com', 'EXAMPLE@TO.NET'
text_content = 'This is an important message.'
msg = EmailMultiAlternatives(
subject,
text_content,
from_email,
[to,],
headers={'X-SMTPAPI': header.json_string()},
)
msg.send()
You also need to install a smtpapi package by pip install smtpapi
1
from django.core.mail import EmailMultiAlternatives
from smtpapi import SMTPAPIHeader
smtp_header = SMTPAPIHeader()
smtp_header.set_unique_args({'customerAccountNumber': '12345','activationAttempt': '1'})
subject, from_email, to = 'hello', 'hello@FROM.com', 'AABC@TO.NET'
text_content = 'This is message.'
msg = EmailMultiAlternatives(
subject,
text_content,
from_email,
[to,],
headers={'X-SMTPAPI': smtp_header.json_string()},
)
msg.send()
- [Django]-Django user in tornado
- [Django]-Reverse for 'edit' with no arguments not found. 1 pattern(s) tried: ['articles/edit/(?P<pk>[0-9]+)/$']
Source:stackexchange.com