【发布时间】:2019-01-25 05:32:51
【问题描述】:
这是我的应用程序的 settings.py
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'hk7206210@gmail.com'
EMAIL_HOST_PASSWORD = '*********'
EMAIL_PORT = '587'
EMAIL_USE_TLS = True
forms.py
from django import forms
class contactForm(forms.Form):
name = forms.CharField(required= True,max_length = 100,help_text = '100
character Max.')
email = forms.EmailField(required = True)
comment = forms.CharField(widget = forms.Textarea)
views.py
from django.shortcuts import render
from .forms import contactForm
from django.core.mail import send_mail
from django.conf import settings
# Create your views here.
def contact(request):
form = contactForm(request.POST or None)
if form.is_valid():
name = form.cleaned_data['name']
comment = form.cleaned_data['comment']
subject = 'Message from Matrimonial.com'
message = '%s %s' %(comment,name)
emailFrom = form.cleaned_data['email']
emailTo = [settings.EMAIL_HOST_USER]
send_mail(subject, message,emailFrom,emailTo)
context = locals()
template = 'contact.html'
return render(request,template,context)
问题是发件人和收件人来自同一电子邮件地址,来自 hk7206210@gmail.com 也是 hk7206210@gmail.com 我搜索了很多但找不到解决方案,帮我解决这个错误#
【问题讨论】:
标签: python django email authentication gmail