我创建了一个函数,当重定向到特定 url 时会向特定用户发送邮件。它一直工作到今天。但是,今天当它被重定向到 url 时,电子邮件显示在终端中,而不是在接收者的收件箱中。我在代码中附加了邮件功能和设置。
视图.py
def mail(request,pk):
pr = UserProfile.objects.get(pk=pk)
subject = "Greetings"
msg = "Congratulations for your success"
to = 'urvi0728@gmail.com'
res = send_mail(subject, msg, settings.EMAIL_HOST_USER, [to])
if(res == 1):
msg = "Mail Sent Successfuly"
else:
msg = "Mail could not be sent"
return HttpResponse(msg)
设置.py
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = '*****@gmail.com'
EMAIL_HOST_PASSWORD = '*********'
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'