【问题标题】:Using Sendgrid API to send emails使用 Sendgrid API 发送电子邮件
【发布时间】:2021-08-07 19:49:21
【问题描述】:

我正在使用 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))

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

【问题讨论】:

  • 您使用的是哪个版本的 SendGrid python 库?
  • 我一直在使用 sendgrid 6.7.1

标签: python sendgrid sendgrid-api-v3 sendgrid-templates


【解决方案1】:

这里是 Twilio SendGrid 开发人员宣传员。

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

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

【讨论】:

    猜你喜欢
    • 2016-11-30
    • 2019-06-14
    • 2018-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多