【发布时间】:2017-08-21 05:30:05
【问题描述】:
我想让访问我网站的人能够向我的雅虎邮箱发送电子邮件。我怎样才能做到这一点?现在,我还没有邮件服务器。有必要吗?这个想法是让发送电子邮件的人填写他的电子邮件、主题和消息,然后将其发布到我的雅虎电子邮件。
def email(request):
if request.method == 'GET':
form = ContactForm()
else:
form = ContactForm(request.POST)
if form.is_valid():
subject = request.POST.get['subject']
email = request.POST.get['email']
message = request.POST.get['message']
if subject and email and message:
try:
send_mail(subject, message, email, ['my_email@yahoo.com'], fail_silently=False,)
except BadHeaderError:
return HttpResponse('Invalid header found.')
return redirect('thanks')
else:
return HttpResponse('Make sure to have all fields filled.')
return render(request,"mywebsit/contact.html", {'form':form})
表单呈现正常,但是当我按下发送时,它的行为就好像它已经发送了消息,但是当我打开我的雅虎邮件时,那里没有任何新内容。
我读到有必要在settings.py 配置一些东西,但据我所知,它是用来发送的,而我想要的是接收。
尽管如此,我尝试配置它,
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.mail.yahoo.com'
EMAIL_PORT = 465
EMAIL_HOST_USER = 'email@yahoo.com'
EMAIL_HOST_PASSWORD = 'yahoopassword'
DEFAULT_FROM_EMAIL = 'email@yahoo.com'
DEFAULT_TO_EMAIL = 'email@yahoo.com'
然后我得到的是这个错误:
smtplib.SMTPServerDisconnected:连接意外关闭
我该怎么办?
【问题讨论】: