带有 SMTP 后端的 django send_mail 无法发送电子邮件

发布于 2024-11-19 18:02:03 字数 1005 浏览 1 评论 0原文

我正在 ubuntu 堆栈上部署 Django 项目,并使用托管在 Amazon EC2 上的 postfix SMTP 邮件服务器。我可以使用 Linux 邮件程序从服务器发送电子邮件。但是当我尝试使用 django.core.mail.send_mail 发送电子邮件时,从未收到电子邮件。

以下是我的设置:

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'

我将其他所有内容保留为默认值。

我尝试了

python manage.py shell

然后在 shell 中,我做了

from django.core.mail import *
send_mail(
    'TEST',
    'THIS IS A TEST',
    '[email protected]',
    ['[email protected]'],
    fail_silently=False,
    )

This returns 1,但我从未在目的地收到任何消息 ('[电子邮件受保护]' 例子)。

有关于如何配置 SMTP 服务器以与 Django 邮件系统一起使用的教程吗?谢谢。

I am deploying a Django project on an ubuntu stack with a postfix SMTP mail server, hosted on Amazon's EC2. I can send out email from the server using the Linux mail program. But when I try to send email using django.core.mail.send_mail, the email is never received.

Here are my settings:

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'

I left everything else as default.

I tried

python manage.py shell

Then in the shell, I did

from django.core.mail import *
send_mail(
    'TEST',
    'THIS IS A TEST',
    '[email protected]',
    ['[email protected]'],
    fail_silently=False,
    )

This returns 1, but I never received any message at the destination ('[email protected]' in the example).

Is there a tutorial on how to configure a SMTP server to work with Django's mail system? Thanks.

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

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

发布评论

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

评论(1

爱已欠费 2024-11-26 18:02:03

我假设您确实在 settings.py 中指定了 EMAIL_HOST、EMAIL_PORT、EMAIL_HOST_USER 和 EMAIL_HOST_PASSWORD,对吧?

详细解释了默认的 django.core.mail.backends.smtp.EmailBackend 如何工作 -
https://docs.djangoproject.com/en/dev/topics/email/
https://docs.djangoproject.com/en/dev/topics/email/#smtp-backend

特别是对于您的电子邮件端口,您是否在 EC2 安全组下打开了 smtp 端口?如果您在 postfix 配置期间将 SMTP 端口保留为默认值,则 SMTP 端口通常默认为 25,并且在创建 EC2 实例时打开该端口非常重要。

I assume that you did specify your EMAIL_HOST, EMAIL_PORT, EMAIL_HOST_USER and EMAIL_HOST_PASSWORD in your settings.py right?

A detailed explanation of how the default django.core.mail.backends.smtp.EmailBackend works is explained -
https://docs.djangoproject.com/en/dev/topics/email/
https://docs.djangoproject.com/en/dev/topics/email/#smtp-backend

And specifically for your email port, you did open your port for smtp under EC2's security group? SMTP port usually defaults to 25 if you left it as default during your postfix configuration and it is important that you have opened up that port when you created your EC2 instance.

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