2013-11-02 78 views
6

我想配置Django的send_email,以便我可以發送密碼重置電子郵件給用戶。到目前爲止,我沒有運氣讓它工作。我已經建立了一個基本的Gmail帳戶(沒有谷歌應用程序等),並在我的Django settings.py我有:Django通過smtp.gmail.com發送電子郵件的問題

EMAIL_HOST  = 'smtp.gmail.com' 
EMAIL_HOST_PASSWORD = 'my_password' 
EMAIL_HOST_USER = '[email protected]' 
EMAIL_PORT  = 587 
MAIL_USE_TLS = True 

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' 
DEFAULT_FROM_EMAIL = '[email protected]' 

然後我嘗試從做測試:

python manage.py shell 
>>> from django.core.mail import send_mail 
>>> send_mail('test', 'test', '[email protected]', ['[email protected]']) 

我得到錯誤信息

Traceback (most recent call last): 
    File "<console>", line 1, in <module> 
    File "C:\Program Files\Python27\lib\site-packages\django\core\mail\__init__.py 
", line 62, in send_mail 
    connection=connection).send() 
    File "C:\Program Files\Python27\lib\site-packages\django\core\mail\message.py" 
, line 255, in send 
    return self.get_connection(fail_silently).send_messages([self]) 
    File "C:\Program Files\Python27\lib\site-packages\django\core\mail\backends\sm 
tp.py", line 88, in send_messages 
    new_conn_created = self.open() 
    File "C:\Program Files\Python27\lib\site-packages\django\core\mail\backends\sm 
tp.py", line 55, in open 
    self.connection.login(self.username, self.password) 
    File "C:\Program Files\Python27\lib\smtplib.py", line 577, in login 
    raise SMTPException("SMTP AUTH extension not supported by server.") 
SMTPException: SMTP AUTH extension not supported by server. 

有沒有人有一個想法是怎麼回事!任何提示表示讚賞!

回答

4

確保您還設置EMAIL_BACKEND設置:

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

是這行是在我的settings.py。還是行不通。 –

13

您已在設置一個錯字。應該使用EMAIL_USE_TLS而不是MAIL_USE_TLS來設置TLS。連接到587時不使用TLS會生成此錯誤。

1

當您刪除郵件擴展名時,錯誤更改爲其他錯誤。但在大多數情況下,這不是真正的問題。一旦你確實完成了你的設置,它適用於擴展和沒有。

EMAIL_HOST_USER = 'my_account' 

訪問https://myaccount.google.com/security並檢查它是否在打開允許不夠安全的應用在底部設置工作。

相關問題