从Django发送邮件

dojqjjoe  于 2023-10-21  发布在  Go
关注(0)|答案(1)|浏览(96)

所以,我尝试从Django发送电子邮件。我得到了错误。我已经用尽了ChatGPT,谷歌。最后我来寻求帮助。我已经遵循了这么多的教程,但无论我做什么,我得到这个错误。

[WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

我已经检查了我所有的帐户信息,密码,其他细节100的时间,所有这些都应该是什么。
这里是我的settings.py

EMAIL_BACKEND= 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST= 'smtp.gmail.com'
EMAIL_USE_TLS= True
EMAIL_PORT= 587
EMAIL_HOST_USER= '[email protected]'
EMAIL_HOST_PASSWORD= 'app password generated by google'

这里是views.py

from django.core.mail import send_mail
from django.http import HttpResponse

def simple_mail(request):
    send_mail(
              subject = 'test email 1',
              message = 'this is a test email',
              from_email = '[email protected]',
              recipient_list = ['[email protected]'],
              fail_silently=False,
                )
   return HttpResponse('OK')

免费邮件的配额还没有结束,因为我没有发送任何。此外,我正在测试与localhost和互联网是工作。

nuypyhwy

nuypyhwy1#

我想你用的端口不对,应该是465
像这样更改设置。
EMAIL_PORT = 465

相关问题