从Django中Godaddy托管的电子邮件发送电子邮件时出错

时间:2019-06-16 20:14:29

标签: django django-settings django-mailer

在godaddy上有一封邮件hotwd说verify@mydomain.com 我想使用EmailMultipleAlternative从后端发送邮件。但是我收到错误消息,说“连接意外关闭” 这是我的观点和设置: views.py

subject ='欢迎使用MySite!确认您的电子邮件。'         htmly = get_template('account_activation_email.html')

    d = { 'user': user, 'domain':current_site.domain, 'uemail':urlsafe_base64_encode(force_bytes(user.email)), 'uid':urlsafe_base64_encode(force_bytes(user.pk)), 'token': account_activation_token.make_token(user)}

    text_content = ""
    html_content = htmly.render(d)
    msg = EmailMultiAlternatives(subject, text_content, '', [user.email])
    msg.attach_alternative(html_content, "text/html")
    try:
        msg.send()
    except Exception as e:
        print(e) #this throws connection closed unexpectedly!
        print("Error while sending email!")
    user.save()

settings.py

MAIL_USE_TLS = True
EMAIL_HOST = config('EMAIL_HOST')
EMAIL_HOST_USER = verify@mysite.com
EMAIL_HOST_PASSWORD = 'randompass'
EMAIL_PORT = config('EMAIL_PORT')
DEFAULT_FROM_EMAIL = 'MySte Verification <verify@mysite.com>'

请帮助我!

0 个答案:

没有答案