Py学习  »  Django

开发中的Django电子邮件发送

Ginger Bread • 5 年前 • 2274 次点击  

以下是settings.py文件中的我的属性:

EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'infobot9@gmail.com'
EMAIL_HOST_PASSWORD = os.environ.get('EMAIL_HOST_PASSWORD')
EMAIL_PORT = 587

以下是我的发送电子邮件方法:

from django.core.mail import send_mail 


def sendConfirmEmail(email, instance, code):
    mail_subject = 'Confirmation code {}'.format(code)
    message = render_to_string("msg.html", {
       'user': instance,
       'code': code

    })
    to_email = email
    send_mail(mail_subject, message, 'infobot9@gmail.com', [to_email], 
              fail_silently=False)

我的Django电子邮件发送方法在本地主机上运行良好。在将它部署到Heroku之后,我在Gmail设置中允许从未知设备登录。Gmail不允许服务器登录到我的帐户并向我发送消息:

阻止了spicious登录尝试

infobot9@gmail.com

有人试图使用为他们设置的密码登录您的帐户。如果不是你,我们建议你尽快更改密码。



未知设备



4月4日11:39



靠近这个地方:爱尔兰都柏林

176.34.163.6(IP地址)

我应该在我的 settings.py 文件或我需要更改我的Gmail帐户设置?

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/50211
 
2274 次点击  
文章 [ 2 ]  |  最新文章 5 年前