Django的send_mail [错误111]拒绝连接

我必须通过从Django中发送我的电子邮件一个问题:Django的send_mail [错误111]拒绝连接

Django Version: 1.11.3 

Exception Type: error

Exception Value:

[Errno 111] Connection refused

Exception Location: /usr/lib/python2.7/socket.py in create_connection, line 571

Python Version: 2.7.6

settings.py

EMAIL_USE_TLS = True 

EMAIL_HOST = 'smtp.gmail.com'

EMAIL_HOST_USER = '[email protected]'

EMAIL_HOST_PASSWORD = '******'

EMAIL_PORT = 587

views.py

... 

from django.core.mail import send_mail

...

def testmail(request):

send_mail('subj2', 'message', '[email protected]', ['[email protected]'])

return HttpResponse('ok')

但,当我尝试从控制台发送消息时:

python manage.py shell 

from django.core.mail import send_mail

send_mail('subj2', 'message', '[email protected]', ['[email protected]'])

它的工作,我sucessfuly收到我的消息。

回答:

这是我所做的。

views.py

from django.core.mail import EmailMessage 

...

email = EmailMessage('title', 'body', to=[mailid])

email.send()

...

settings.py

EMAIL_USE_TLS = True 

EMAIL_HOST = 'smtp.gmail.com'

EMAIL_HOST_USER = '[email protected]'

EMAIL_HOST_PASSWORD = 'password'

EMAIL_PORT = 587

并确保已启用https://myaccount.google.com/lesssecureapps。

以上是 Django的send_mail [错误111]拒绝连接 的全部内容, 来源链接: utcz.com/qa/257948.html

回到顶部