Django-SMTPAuthenticationError

title: Django SMTPAuthenticationError
type: categories
date: 2017-07-29 09:58:38
categories: Python3

tags: [Django, Heroku, SMTP]

在Django应用中,利用SMTP发送验证邮件,本地的环境完全没问题,但当将Django应用部署到Heroku上后,邮件发送失败,报SMTPAuthenticationError错误。解决这个问题发费时间较长,记录一下。

这个问题针对【 Gmail 】邮。

setting.py
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'jmspvu@gmail.com'
EMAIL_HOST_PASSWORD = '*******'
DEFAULT_FROM_EMAIL = 'jmspvu@gmail.com'
views.py
        try:
            sendEmail = EmailMessage(subject='用户注册', body=message, to=[loginName])
            sendEmail.send(fail_silently=False)
            print(loginName)
            msg = {"isSuccess": True,
                   "msg": 'Verification code sent successfully'}
            return HttpResponse(json.dumps(msg), content_type='application/json')
        except:
            # msg = {"isSuccess": False,
            #        "msg": 'Verification code sent failure'}
            # return HttpResponse(json.dumps(msg), content_type='application/json')
            raise Exception
在Heroku上的报错

SMTPAuthenticationError

During handling of the above exception ((534, b'5.7.14 Please log in via your web browser and\n5.7.14 then try again.\n5.7.14 Learn more at\n5.7.14 https://support.google.com/mail/answer/78754 q15sm15913999qkl.26 - gsmtp')), another exception occurred:

解决方法(Gmail)

1、检查账号、密码是否匹配;

2、开启gmail邮箱的不安全应用:https://myaccount.google.com/lesssecureapps

3、授权账号访问权限(我的就因为开启这个,浪费了那么多时间)https://accounts.google.com/DisplayUnlockCaptcha

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值