通过Gmail发送电子邮件使用Django和Python
问题描述:
我发现了很多关于使用Django发送邮件的职位,但我已经是Gmail的一个具体问题:通过Gmail发送电子邮件使用Django和Python
这里是我的设置:
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? 我还检查了谷歌的设置,如“从访问安全性较低的应用程序”和类似
预先感谢您!
编辑
我已允许不够安全的应用并点击解锁验证码
答
你也可以试试这个。
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
答
喜请添加电子邮件ID不extentio即
EMAIL_HOST_USER = "myemail"
已经回答[http://stackoverflow.com/questions/26697565/django-smtpauthenticationerror](http://stackoverflow gmail的。 COM /问题/ 26697565/Django的smtpauthenticationerror) – betonimig
它并没有帮助。我已经完成了...但问题仍然是 – scotch