gpt4 book ai didi

Django SendGrid 如何在 EmailMultiAlternatives 邮件对象中传递 unique_args

转载 作者:行者123 更新时间:2023-12-05 00:55:26 25 4
gpt4 key购买 nike

SendGrid 提供通过 unique_args 的能力带有电子邮件,以便识别 Event webhook. 中的电子邮件但问题是我无法弄清楚如何在 Django 中使用电子邮件发送这些 un​​ique_args。这就是我目前正在尝试的方式:

from django.core.mail import EmailMultiAlternatives

header ={
"unique_args": {
"customerAccountNumber": "55555",
"activationAttempt": "1",
"New Argument 1": "New Value 1",
"New Argument 2": "New Value 2",
"New Argument 3": "New Value 3",
"New Argument 4": "New Value 4"
}
}

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=header,
)
msg.send()

最佳答案

好的,所以我终于找到了解决方案。最后,我想出了如何使用 Django EmailMultiAlternatives 将 unique_args 发送到 SendGrid。这是我的工作解决方案:

    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()

你还需要通过pip install smtpapi

安装一个smtpapi包

关于Django SendGrid 如何在 EmailMultiAlternatives 邮件对象中传递 unique_args,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64575583/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com