简体   繁体   中英

Django SMTP error 530

Hi I am trying to send test email from my contact page using Django project. I have set up my settings.py in a following way:

ALLOWED_HOSTS = []
EMAIL_USE_TLS=True
EMAIL_HOST="smtp.gmail.com"
EMAIL_PORT=587
EMAIl_HOST_USER="myemail@gmail.com"
EMAIL_HOST_PASSWORD="mypassword"

In my views.py I have added this function for sending email from contact form:

 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)

But I am always getting following error after submission in contact form!!

SMTPSenderRefused at /contact/ (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')

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']

Anyone I have any idea why I am getting this error? is there anyway to solve this problem? Thanks

EMAIl_HOST_USER="myemail@gmail.com"

I think it should be EMAIL_HOST_USER .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM