如何在django中发送电子邮件 [英] how to send email in django

查看:53
本文介绍了如何在django中发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在settings.py中的设置,但不向gmail帐户发送任何邮件.您能告诉我如何将确认邮件发送到邮件吗在此处输入代码

my settings in settings.py but not sending any mails to gmail account. can u please expalin me how to send confirm mail to mailenter code here

EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'myemail.com'
EMAIL_HOST_PASSWORD = 'mypassword'
EMAIL_PORT = 587

我在cmd中收到成功消息,但没有发送电子邮件给我的ID

I am getting success message in cmd but not sending email to my id

def signup(request):
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            user = form.save(commit=False)
            user.save()
            current_site = get_current_site(request)
            print(current_site)
            subject = 'Activate Your MySite Account'
            message = render_to_string('account_activation_email.html', {
                'user': user,
                'domain': current_site.domain,
                'uid': urlsafe_base64_encode(force_bytes(user.pk)),
                'token': account_activation_token.make_token(user),
            })
            from_email =settings.EMAIL_HOST_USER
            print(from_email,"email here")
            # to_email = [from_email,'sridharadhi50@gmail.com']
            to_email = form.cleaned_data.get('email')
            email = EmailMessage(
                subject, message, to=[to_email]
            )
            email.send()
            # user.email_user(subject, message)
            return redirect('account_activation_sent')enter code here

推荐答案

您应提供EMAIL_BACKEND

You should give EMAIL_BACKEND

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'

EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'mail@gmail.com'
EMAIL_HOST_PASSWORD = 'password'
EMAIL_PORT = 587

工作正常.

这篇关于如何在django中发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆