Django配置在服务器上发送电子邮件

时间:2014-10-25 22:15:33

标签: python django

我真的需要你的帮助。大约一个星期我正在尝试在我的服务器上配置邮件。我使用nginx - > uwsgi - > django申请。 问题是邮件服务器只能使用以下后端:

class SSLEmailBackend(EmailBackend):
    def open(self):
        if self.connection:
            return False
        try:
            self.connection = smtplib.SMTP_SSL(
                self.host, self.port, local_hostname=DNS_NAME.get_fqdn())

            if self.username and self.password:
                self.connection.ehlo()
                # Remove CRAM-MD5 authentication method
                self.connection.esmtp_features['auth'] = 'PLAIN LOGIN'
                self.connection.login(self.username, self.password)
            return True
        except:
            if not self.fail_silently:
                raise

我的设置:

EMAIL_BACKEND = "my_app.backends.SSLEmailBackend"
EMAIL_HOST = "mail.my_mail_server.com"
EMAIL_PORT = 465
EMAIL_HOST_USER = "host@myhost.com"
EMAIL_HOST_PASSWORD = "my_pass"
DEFAULT_FROM_EMAIL = "host@myhost.com"

在当地,它完全有效!

可以在服务器控制台中发送消息而没有任何错误的最奇怪的事情:

>> from django.core.mail import send_mail
>> send_mail('test email', 'hello world', '', ['my_test@gmail.com'])

当我尝试注册新用户时出现问题。我使用Django-userena后端进行注册。注册成功,但电子邮件仅在服务器上发送到/ var / mail / user1

电子邮件文字:

rom MAILER-DAEMON Sun Oct 26 02:06:01 2014
Return-path: <>
Envelope-to: webmaster@localhost
Delivery-date: Sun, 26 Oct 2014 02:06:01 +0400
Received: from Debian-exim by mail.my_mail_server.com with local (Exim 4.80)
        id 1Xi9TF-0002Wp-Ml
        for webmaster@localhost; Sun, 26 Oct 2014 02:06:01 +0400
X-Failed-Recipients: test@test.com
Auto-Submitted: auto-replied
From: Mail Delivery System <Mailer-Daemon@elib.rshu.ru>
To: webmaster@localhost
Subject: Mail delivery failed: returning message to sender
Message-Id: <E1Xi9TF-0002Wp-Ml@mail.my_mail_server.com>
Date: Sun, 26 Oct 2014 02:06:01 +0400
Status: O

This message was created automatically by mail delivery software.

A message that you sent could not be delivered to one or more of its
recipients. This is a permanent error. The following address(es) failed:

  test@test.com
    Mailing to remote domains not supported
------ This is a copy of the message, including all the headers. ------
Return-path: <webmaster@localhost>
Received: from localhost ([::1] helo=mail.my_mail_server.com)
        by mail.my_mail_server.com with esmtp (Exim 4.80)
        (envelope-from <webmaster@localhost>)
        id 1Xi9TF-0002Wm-Lv
for test@test.com; Sun, 26 Oct 2014 02:06:01 +0400
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Subject: =?utf-8?b?0KDQtdCz0LjRgdGC0YDQsNGG0LjRjyDQsiDRjdC70LXQutGC0YDQvtC90L0=?=
 =?utf-8?b?0L7QuSDQsdC40LHQu9C40L7RgtC10LrQtSDQoNCT0JPQnNCj?=
From: webmaster@localhost
To: test@test.com
Date: Sat, 25 Oct 2014 22:06:01 -0000
....

我一直在检查userena,nginx等。我无法理解可能是什么问题。为什么它在本地和服务器控制台上工作可以发送消息。请帮忙。

1 个答案:

答案 0 :(得分:0)

您的邮件服务器未设置为接受远程邮件转发。来自服务器的错误消息是“邮件到不支持的远程域”。因此,无论您连接到哪个邮件服务器,都无法识别您的Web服务器是“受信任的用户”,应该接受和转发邮件。我会尝试让您的邮件服务提供商将您的服务器列入白名单以发送电子邮件。