2016-11-17 117 views
-1

我發現了很多關於使用Django發送郵件的職位,但我已經是Gmail的一個具體問題:通過Gmail發送電子郵件使用Django和Python

error image

這裏是我的設置:

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' 
EMAIL_HOST = "smtp.gmail.com" 
EMAIL_HOST_USER = "[email protected]" 
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER 
EMAIL_HOST_PASSWORD = 'mypassword 
EMAIL_PORT = 587 
EMAIL_USE_TLS = True 

,我的看法是:

from django.core.mail import EmailMessage, send_mail 

    if request.method == 'POST': 
     name = request.POST.get('name','') 
     email = request.POST.get('email','') 
     subject = request.POST.get('subject','') 
     text = request.POST.get('text','') 

     message = 'From: ' + email + '\n\n\n' + text 

     send_mail(subject, message, '[email protected]', ['[email protected]'], fail_silently=False) 

能否請你告訴我,爲什麼我得到這個電子RROR? 我還檢查了谷歌的設置,如「從訪問安全性較低的應用程序」和類似

預先感謝您!

編輯

我已允許不夠安全的應用並點擊解鎖驗證碼

+1

已經回答[http://stackoverflow.com/questions/26697565/django-smtpauthenticationerror](http://stackoverflow gmail的。 COM /問題/ 26697565/Django的smtpauthenticationerror) – betonimig

+0

它並沒有幫助。我已經完成了...但問題仍然是 – scotch

回答

0

你也可以試試這個。

import smtplib 

def send_mail(request): 
    try: 
     subject = "Email Subject" 
     description ="description" 

     gmail_user = "[email protected]" # email id from where you want send mail 
     gmail_pwd ="password" 
     FROM = 'Admin: <[email protected]>' 
     TO = "[email protected]" #email id where you want send mail 
     TEXT = description 
     SUBJECT = subject 
     server = smtplib.SMTP_SSL() 
     server = smtplib.SMTP("smtp.gmail.com", 587) 
     server.ehlo() 
     server.starttls() 

     server.login(gmail_user, gmail_pwd) 
     message = """From: %s\nTo: %s\nSubject: %s\n\n%s """ % (FROM, ", ".join(TO), SUBJECT, TEXT) 
     server.sendmail(FROM, TO, message) 
     server.quit()  
    except Exception,e: 
     print 'exception',e 
+0

它會產生相同的錯誤... – scotch

0

喜請添加電子郵件ID不extentio即

EMAIL_HOST_USER = "myemail"