您好我正在尝试使用Django项目从我的联系页面发送测试电子邮件。我已按以下方式设置了settings.py:
ALLOWED_HOSTS = []
EMAIL_USE_TLS=True
EMAIL_HOST="smtp.gmail.com"
EMAIL_PORT=587
EMAIl_HOST_USER="myemail@gmail.com"
EMAIL_HOST_PASSWORD="mypassword"
在我的views.py中,我添加了此功能,用于从联系表单发送电子邮件:
def contact(request):
title="Contact"
form = ContactForm(request.POST or None)
contextcontact={"title":title, "form":form}
if form.is_valid():
form_email = form.cleaned_data.get("email")
form_full_name = form.cleaned_data.get("full_name")
form_full_name=form_full_name.strip()
form_message = form.cleaned_data.get("message")
subject='Site contact form'
from_email=settings.EMAIL_HOST_USER
to_email=[from_email, 'anotheremail@gmail.com']
contact_message="%s: %s via %s"%(
form_full_name,
form_message,
form_email)
send_mail(subject,message,from_email,to_email,fail_silently=False)
contextcontact={"title":"Thank you for your enquiry","hide":True}
return render(request, 'contact.html', contextcontact)
但是在提交联系表格后我总是得到以下错误!!
SMTPSender拒绝/ contact / (530,' 5.5.1需要验证。了解更多信息,请访问\ n5.5.1 https://support.google.com/mail/answer/14257 q2sm41488622pfq.88 - gsmtp',u' webmaster @ localhost')
Request Method: POST
Request URL: http://172.16.1.93:8000/contact/
Django Version: 1.8.9
Exception Type: SMTPSenderRefused
Exception Value:
(530, '5.5.1 Authentication Required. Learn more at\n5.5.1 https://support.google.com/mail/answer/14257 q2sm41488622pfq.88 - gsmtp', u'webmaster@localhost')
Exception Location: /usr/lib/python2.7/smtplib.py in sendmail, line 731
Python Executable: /usr/bin/python
Python Version: 2.7.6
Python Path:
['/home/paul/Desktop/djangoproject/tracker/mysite',
'/usr/lib/python2.7',
'/usr/lib/python2.7/plat-x86_64-linux-gnu',
'/usr/lib/python2.7/lib-tk',
'/usr/lib/python2.7/lib-old',
'/usr/lib/python2.7/lib-dynload',
'/usr/local/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages/PILcompat',
'/usr/lib/python2.7/dist-packages/gtk-2.0',
'/usr/lib/pymodules/python2.7',
'/usr/lib/python2.7/dist-packages/ubuntu-sso-client']
任何人我都知道为什么会收到此错误?反正有没有解决这个问题? 感谢
答案 0 :(得分:0)
EMAIL_HOST_USER =" myemail@gmail.com"
我认为它应该是IHello stub = (IHello)UnicastRemoteObject.exportObject(obj, 20200);
Registry registry = LocateRegistry.createRegistry(20222);
registry.bind("A Say Hello Remote Object", stub);
。