0
嗨我想從我的聯繫頁面使用Django項目發送測試電子郵件。我已經建立了我的settings.py以下列方式:Django SMTP錯誤530
ALLOWED_HOSTS = []
EMAIL_USE_TLS=True
EMAIL_HOST="smtp.gmail.com"
EMAIL_PORT=587
EMAIl_HOST_USER="[email protected]"
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, '[email protected]']
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在/聯繫人/ (530, '5.5.1要求進行驗證,瞭解更多\ n5.5.1 https://support.google.com/mail/answer/14257 q2sm41488622pfq.88 - gsmtp',u'webmaster @本地')
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'[email protected]')
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']
任何人我有任何想法,爲什麼我得到這個錯誤?反正有解決這個問題嗎? 感謝
你嘗試去錯誤信息中的網址嗎? –
我讓我的Gmail更加安全並被接受'允許訪問您的Google帳戶' – Paul85