请问我已经尝试过此代码,但不幸的是它无法正常工作 有错误: SMTPServer在/断开连接 连接意外关闭:[Errno 104]对等重置连接
Setting.py
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'shabbirfast@gmail.com'
EMAIL_HOST_PASSWORD = '*****'
EMAIL_PORT = 587
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
Views.py
from django.shortcuts import render
from django.core.mail import send_mail
from django.conf import settings
from django.http import HttpResponse
def sendemail(request):
subject = 'Test Mail'
message = 'This is an automatic massage HELLO from django.'
email_from = settings.EMAIL_HOST_USER
recipient_list = ['shabbir@xcodes.net']
try:
send_mail(subject, message, email_from,
recipient_list,fail_silently=False)
return HttpResponse("SEND Confirm")
except Exception as e:
raise e