Django EmailMultiAlternatives在发送时意外关闭连接

时间:2019-06-15 19:51:04

标签: django django-views django-settings

我正在使用Godaddy邮件从django后端发送邮件,但它给我“连接意外关闭”。我的代码如下:

views.py

current_site = get_current_site(request)
            subject = 'Welcome to MySite! Confirm Your email.'
            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 BadHeaderError:
                print("Error while sending email!")
            user.save()

setting.py

EMAIL_BACKEND = 'django_smtp_ssl.SSLEmailBackend'
EMAIL_USE_SSL = True
# EMAIL_USE_TLS = True
EMAIL_HOST = config('EMAIL_HOST')
EMAIL_HOST_USER = config('EMAIL_HOST_USER')
EMAIL_HOST_PASSWORD = config('EMAIL_HOST_PASSWORD')
EMAIL_PORT = 465
SERVER_EMAIL = 'verify@mysite.com'
DEFAULT_FROM_EMAIL = 'Verification <verify@mysite.com>'

请帮助我...

0 个答案:

没有答案