【问题标题】:Django SMTP error 530Django SMTP 错误 530
【发布时间】:2016-03-15 20:10:23
【问题描述】:

您好,我正在尝试使用 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)

但是我在联系表单中提交后总是出现以下错误!

SMTPSenderRefused at /contact/ (530, '5.5.1 Authentication required. 了解更多信息\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']

有人知道我为什么会收到此错误吗?有没有办法解决这个问题? 谢谢

【问题讨论】:

  • 您是否尝试转到错误消息中引用的 url?
  • 我降低了我的 gmail 的安全性并接受了“允许访问您的 Google 帐户”

标签: python django email gmail smtplib


【解决方案1】:

EMAIl_HOST_USER="myemail@gmail.com"

我觉得应该是EMAIL_HOST_USER

【讨论】:

    猜你喜欢
    • 2020-06-14
    • 1970-01-01
    • 2018-10-07
    • 1970-01-01
    • 1970-01-01
    • 2015-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多