簡體   English   中英

django 電子郵件消息不起作用

[英]django EmailMessage not work

代碼:

                email1 = EmailMessage(from_email='cc@outlook.com', to=['cc@outlook.com'])
                print "email1:", type(email1)
                email1.attach(title + '.pdf', pdf, 'application/pdf')
                try:
                        print "email........"
                        print email1.send(fail_silently=False)
                except Exception as e:
                        print "Exception when sending emails:", e

輸出:

email1: <class 'django.core.mail.message.EmailMessage'>
email........
1

設置:

EMAIL_HOST = 'localhost'
EMAIL_PORT = 25
DEFAULT_FROM_EMAIL = "firstname.lastname@company.com"
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'

沒有例外,沒有錯誤信息。 但它不能發送電子郵件。 不知道為什么以及如何調試

當我將 localhost 更改為我的主機名時,出現以下錯誤:

Exception when sending emails: [Errno 111] Connection refused

謝謝

您需要允許不太安全的應用程序,您可以通過單擊下面的鏈接來實現

https://www.google.com/settings/security/lesssecureapps

也試試這個

https://accounts.google.com/DisplayUnlockCaptcha

如果仍然無效,請嘗試更改 gmail 的密碼

settings.py應該是

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'your-acount@gmail.com'
EMAIL_HOST_PASSWORD = 'your-gmail-password'
EMAIL_PORT = 587
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER

暫無
暫無

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

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