我一直在尝试使用我的Gmail帐户发送电子邮件,但接收器没有收到任何东西,为什么会这样?
views.py
from django.shortcuts import render
from django.core.mail import send_mail
def index(request):
if request.method == "POST":
receiver = request.POST.get("receiver")
from_email = "myemailaddress"
recipient_list = [receiver]
subject = "Just sending message"
message = "If you are seeing this then this possibly worked"
send_mail(subject, message, from_email, recipient_list, fail_silently=False)
return render(request, 'index.html')
settings.py
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = 'myemailaddress'
EMAIL_HOST_PASSWORD = 'myemailpassword'
我如何处理这个问题
1条答案
按热度按时间2izufjch1#
我想可能是因为谷歌不允许非2fa连接,所以你需要使用应用密码(谷歌帐户-〉安全-〉进入应用密码--〉生成新的邮件密码)
使用此新密码作为连接到gmail的密码。