【问题标题】:does django send_mail() support custom 'from'?django send_mail() 是否支持自定义“发件人”?
【发布时间】:2018-10-10 12:01:07
【问题描述】:

我的 django 应用正在使用 django.core.mailsend_mail 发送电子邮件(通过 SendGrid API)

send_mail(
    subject='foo',
    message=message,
    from_email=settings.DEFAULT_FROM_EMAIL,
    recipient_list=[user.email],
    fail_silently=False,
    html_message=rendered)

电子邮件发送正常,但由于它是从 hi@myapp.com 发送的,因此收件箱中的电子邮件“发件人”别名只会显示为“嗨”,我想让它更详细一些,以便我的收件人知道是谁发送的电子邮件(“来自 AppName 的您好”)。我在 send_mail 文档 (https://docs.djangoproject.com/en/2.1/topics/email/) 中没有看到任何字段用于自定义“发件人”别名字符串的显示方式(除了电子邮件本身),除了“电子邮件的“发件人:”标题将是SERVER_EMAIL 设置”。 django 的send_mail 是否不支持此功能(即,我需要将其重写为使用 sendgrid 库?https://github.com/sendgrid/sendgrid-python?)或者 SendGrid 中是否有配置设置可以自动设置“fromname”?谢谢

是吗

【问题讨论】:

    标签: django sendmail sendgrid email


    【解决方案1】:

    您的示例包括from_email=settings.DEFAULT_FROM_EMAILThe docs 表示允许更详细的形式,例如:

    from_email="Hi from Appname <hi@myapp.com>",
    

    您还可以将DEFAULT_FROM_EMAIL 更改为更详细的形式。但是文档没有说明这是否受支持,所以我不确定这是否会在某处引起问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-09-17
      • 1970-01-01
      • 2014-10-30
      • 2017-06-14
      • 1970-01-01
      • 1970-01-01
      • 2012-06-17
      相关资源
      最近更新 更多