-1
在閱讀Django網站上的文檔後,我對如何使用我的Djagno應用程序配置SMTP後端有點困惑。我有一臺本地交換服務器,它運行的是使用Outlook作爲客戶端的業務域business.com
。如何配置設置以便我使用公司電子郵件(本地交換機)在設置中發送電子郵件?使用Django SMTP
感謝您的幫助!
編輯:
這裏是連接錯誤:
email.send()
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "C:\Users\Evan\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\core\mail\message.py", line 342, in send
return self.get_connection(fail_silently).send_messages([self])
File "C:\Users\Evan\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\core\mail\backends\smtp.py", line 100, in send_messages
new_conn_created = self.open()
File "C:\Users\Evan\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\core\mail\backends\smtp.py", line 58, in open
self.connection = connection_class(self.host, self.port, **connection_params)
File "C:\Users\Evan\AppData\Local\Programs\Python\Python35-32\lib\smtplib.py", line 251, in __init__
(code, msg) = self.connect(host, port)
File "C:\Users\Evan\AppData\Local\Programs\Python\Python35-32\lib\smtplib.py", line 335, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "C:\Users\Evan\AppData\Local\Programs\Python\Python35-32\lib\smtplib.py", line 306, in _get_socket
self.source_address)
File "C:\Users\Evan\AppData\Local\Programs\Python\Python35-32\lib\socket.py", line 711, in create_connection
raise err
File "C:\Users\Evan\AppData\Local\Programs\Python\Python35-32\lib\socket.py", line 702, in create_connection
sock.connect(sa)
ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it
這裏是我的代碼:
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_USE_TLS = True
EMAIL_HOST = 'business.com'
EMAIL_PORT = '25'
EMAIL_HOST_USER = '[email protected]'
EMAIL_HOST_PASSWORD = 'password'
謝謝你的幫助。兩個問題,爲什麼我們使用TLS over SSL,並且我將不得不爲Django製作郵箱才能使用,更正? – GreenSaber
1. TLS用於端口587,SSL用於465.兩者都用於安全連接到SMTP服務器。對於ref:https://docs.djangoproject.com/en/1.10/ref/settings/ 2.是的,你必須創建一個特定於你的項目的郵箱/分發列表,並在提出SMTP請求時給予同樣的內容。 –
我試圖在shell中發送電子郵件,但是我得到WinError 100061,目標機器主動拒絕連接。我不知道爲什麼會發生這種情況,因爲我在我的電子郵件和應用程序郵箱之間手動發送了電子郵件。 – GreenSaber