从 Django 发送邮件

问题描述 投票:0回答:1

所以,我正在尝试从 Django 发送电子邮件。我收到错误。我已经用尽了 ChatGPT、Google。最后我来这里寻求帮助。我已经遵循了很多教程,但无论我做什么,我都会收到此错误。

[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 秒,所有这些都应该是应有的样子。

这是我的设置.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')

免费邮件的配额还没有结束,因为我没有发送任何邮件。另外,我正在使用本地主机进行测试,并且互联网正在运行。

python django smtp gmail
1个回答
0
投票

我认为你使用的端口错误,应该是465

像这样更改设置。

EMAIL_PORT = 465

© www.soinside.com 2019 - 2024. All rights reserved.