如何更改 Django 电子邮件中的发件人地址?

发布于 2024-12-06 23:08:19 字数 482 浏览 0 评论 0原文

正如文档中所述,SERVER_EMAIL< /code> 设置应该更改从 Django (1.3.1) 服务器发送到 ADMINS 的崩溃电子邮件中的“发件人”地址。

但事实并非如此。

这在 1.3.1 中适用吗? (或任何 Django 版本)

Django 坚持只使用我的 EMAIL_HOST_USER - 我的电子邮件登录/实际地址 - 作为发件人地址。我使用 Gmail 作为 SMTP 服务器,所以我想知道这是否与此有关。 Gmail 会阻止这种事情吗?我发誓我以前已经让这个工作过。

这有点烦人,因为我们有多个项目,它们似乎都从同一个地址发送电子邮件,我们必须深入挖掘回溯以查看它是哪个项目。

As noted in the docs, the SERVER_EMAIL setting is supposed to change the 'From' address in crash emails sent to ADMINS from the Django (1.3.1) server.

But it's not.

Does this work for you in 1.3.1? (Or any Django version)

Django insists on just using my EMAIL_HOST_USER - my email login/actual address - as the from address. I'm using Gmail as an SMTP server, so I wonder if that could have something to do with it. Does Gmail block this sort of thing? I swear I've gotten this to work before.

It's a little annoying because we have multiple projects that all seem to be emailing from the same address, and we have to dig through the traceback to see which project it is.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

甜妞爱困 2024-12-13 23:08:19

问题是 Gmail。一直到 smtplib 库,指定了正确的“发件人”地址,并且该库将正确的地址发送到 Gmail。

Gmail 支持页面暗示(尤其是靠近底部的“注意对于 POP/IMAP”用户)您需要在 Gmail 设置下添加一个地址作为“附加电子邮件地址”,以便能够通过 Gmail 的 SMTP 服务器从该地址发送邮件。

这当然需要验证;因为我的“发件人”地址没有收件箱(它是假的!),目前对我来说不可能。但至少这不是 Django bug! : )

(注意:这是 Gmail 阻止您发送垃圾邮件的一种非常明显的方式,我确信这就是他们这样做的原因。)

The problem is Gmail. All the way down to the smtplib library, the correct 'from' address is specified, and this library sends the right address to Gmail.

This Gmail Support page implies (especially near the bottom under "Note for POP/IMAP" users) that you need to add an address as an 'additional email address' under Gmail's settings to be able to send mail from it over Gmail's SMTP servers.

This of course requires verification; since my 'from' address doesn't have an inbox (it's fake!) its not currently possible for me. But at least it's not a Django bug! : )

(Note: this is a pretty obvious way for Gmail to stop you from spamming, I'm sure that's why they do it.)

不离久伴 2024-12-13 23:08:19

从我在代码(1.3.1)中看到的,堆栈跟踪电子邮件是使用 mail_admins 方法发送的,其中 SERVER_EMAIL 作为指定的发件人地址:

mail = EmailMultiAlternatives(u'%s%s' % (settings.EMAIL_SUBJECT_PREFIX, subject),
                message, settings.SERVER_EMAIL, [a[1] for a in settings.ADMINS],
                connection=connection)

定义为:

class EmailMultiAlternatives(EmailMessage):
   [...]
   def __init__(self, subject='', body='', from_email=None, to=None, bcc=None,
            connection=None, attachments=None, headers=None, alternatives=None,
            cc=None):

我建议将跟踪输出放入 EmailMultiAlternatives 中以验证正确的电子邮件地址正在被使用。

From what I can see in the code (1.3.1) the stack trace emails are sent using the mail_admins method with SERVER_EMAIL as the specified from address:

mail = EmailMultiAlternatives(u'%s%s' % (settings.EMAIL_SUBJECT_PREFIX, subject),
                message, settings.SERVER_EMAIL, [a[1] for a in settings.ADMINS],
                connection=connection)

Which is defined as:

class EmailMultiAlternatives(EmailMessage):
   [...]
   def __init__(self, subject='', body='', from_email=None, to=None, bcc=None,
            connection=None, attachments=None, headers=None, alternatives=None,
            cc=None):

I would suggest putting trace output in EmailMultiAlternatives to verify that the proper email address is being used.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文