[英]Django configuration to send email on server
我真的需要你的幫助。 大約一周后,我正在嘗試在服務器上配置郵件。 我使用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等。我不明白這可能是問題所在。 為什么它在本地和服務器控制台上可以工作,所以可以發送消息。 請幫忙。
您的郵件服務器未設置為接受遠程郵件轉發。 來自服務器的錯誤消息是“不支持郵寄到遠程域”。 因此,無論您連接到什么郵件服務器,都無法識別您的Web服務器是“受信任的用戶”,應該接受並轉發郵件。 我會嘗試讓您的郵件服務提供商將您的服務器白名單發送電子郵件。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.