使用Sendgrid API发送电子邮件

2024-05-16 10:23:38 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用Sendgrid API发送电子邮件,但我发送的每封电子邮件都没有Subjet

我的代码如下所示:

def send_notification(sendgrid_key, p_email):
    message = Mail(
        from_email=('my_email@mail.com'),
        to_emails=(p_email),
        subject='subject email',
    )
    message.template_id = 'XXXXXX'

    try:
        sg = SendGridAPIClient(sendgrid_key)
        response = sg.send(message)
    except Exception as e:
        print(str(e))

尽管如此,我已经设置了subjet,我仍然收到没有主题的电子邮件。此外,我的应用程序运行时没有任何错误

I receive the email without subject


Tags: key代码sendapimessage电子邮件emaildef
1条回答
网友
1楼 · 发布于 2024-05-16 10:23:38

Twilio SendGrid开发者福音传道者

使用SendGrid的动态模板时,实际上是在模板中设置主题,而不是通过API。查看此屏幕截图,以查看在模板编辑器中设置主题的位置

enter image description here

如果要动态设置主题,可以在主题中添加模板字符串,并在发送电子邮件时通过动态模板变量进行设置。有关更多信息,请查看creating a dynamic email subject line with mustache templates上的这篇文章

相关问题 更多 >