如何更改 Django 电子邮件中的发件人地址?
正如文档中所述,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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题是 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.)
从我在代码(1.3.1)中看到的,堆栈跟踪电子邮件是使用 mail_admins 方法发送的,其中 SERVER_EMAIL 作为指定的发件人地址:
定义为:
我建议将跟踪输出放入 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:
Which is defined as:
I would suggest putting trace output in EmailMultiAlternatives to verify that the proper email address is being used.