簡體   English   中英

send_mail在本地工作,但不適用於生產托管

[英]send_mail works locally but not on production hosting

以下內容在本地有效,但是當我將其部署到Digital Ocean的生產托管中時,當我在如下所示的shell命令(python manage.py shell)上進行測試時,電子郵件並未發送。 send_mail行剛剛卡在那里,並出現錯誤:[Errno 101]幾分鍾后無法訪問網絡。 如何捕獲電子郵件發送中的錯誤? 請告知如何解決此問題。

from django.core.mail import send_mail
send_mail('test email', 'hello world', 'xxxx@gmail.com', ['xxxx@gmail.com'],fail_silently=False)

# Email settings
EMAIL_USE_TLS = True
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_PASSWORD = 'xxxx' #my gmail password
EMAIL_HOST_USER = 'xxxx@gmail.com' #my gmail username
EMAIL_PORT = 587
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER

您的Django應用設置看起來正確,但是您也應該轉到https://accounts.google.com/DisplayUnlockCaptcha ,並確保啟用對安全性較低的應用的訪問。

如果您使用的是雙重身份驗證,也可以考慮創建應用程序專用密碼

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM