【发布时间】:2021-10-30 22:13:33
【问题描述】:
我目前正在使用此配置来接收来自我的开发和生产服务器的日志记录电子邮件。
ADMINS = [('Test1', 'somename@example.com'), ('Test2', 'someothername@example.com')]
SERVER_EMAIL = "correctsender@example.com"
LOGGING = {
'version': 1,
'handlers': {
'mail_admins': {
'level': 'ERROR',
'class': 'django.utils.log.AdminEmailHandler',
'include_html': True,
},
},
'loggers': {
'django.request': {
'handlers': ['mail_admins'],
'level': 'ERROR',
'propagate': False,
},
}
}
然后使用以下 SMTP 配置发送电子邮件。
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'correctsender@example.com'
EMAIL_HOST_PASSWORD = 'thepassword' # normally loaded from environment
EMAIL_PORT = 587
EMAIL_USE_TLS = True
DEFAULT_FROM_EMAIL = 'correctsender@example.com'
我在 Gmail 中启用了“不太安全的应用程序”。
几天来,我们怀疑错误日志记录已损坏。今天我们确认通过 AdminEmailHandler 发送的邮件没有到达,而所有其他通过普通邮件管道发送的邮件(无论是来自 celery 工人还是直接来自服务器)。
与其他后端的测试表明邮件是由 django 发送的。使用 smtplib 进行的快速测试表明登录没有被阻止。为什么某些邮件会被 Gmail 接受,而其他只是内容不同的邮件却不接受?
另外,Google 中是否有保存被拒绝电子邮件的地方(Google Workspace 只有一个初步报告,没有显示任何内容)?
【问题讨论】:
-
你能确认他们正在被发送吗?
-
邮件肯定被发送,因为更改后端或使用 django shell 使用相同的后端发送不同的邮件都成功。绝对是 google 拒绝 django 错误报告,因为它是恶意的。