Django mail not sending mail

前端 未结 3 1733
野趣味
野趣味 2021-01-28 07:17

I have created a function the would send mail to a particular user when redirected to a particular url. It was working until today. However, today when it gets redirected to the

相关标签:
3条回答
  • 2021-01-28 07:43

    Try this one

    from django.core.mail import EmailMessage 
    
    to_email = your_user_email
    mail_subject = your_message_subject
    message = your_content
    send_message = EmailMessage(mail_subject, message, to=[to_email])
    send_message.content_subtype = "html"
    send_message.send()
    

    As content you can add dictionaries or other data what you wish. If you want to send a template then you can use

    render_to_string

    from django.template.loader import render_to_string
    
    message = render_to_string('path_to_your_template.html', {
            'domain':current_site,
            'email': request.user.email,
            'data' : your_data
        })
    send_message = EmailMessage(mail_subject, message, to=[to_email])
    send_message.content_subtype = "html"
    send_message.send()
    
    0 讨论(0)
  • 2021-01-28 07:48
    email_msg = EmailMessage(subject="subject",
                                         body="content",
                                         to=["xyz@gmail.com"])
    email_msg.send()
    

    use EmailMassage

    0 讨论(0)
  • 2021-01-28 07:50

    Try this one. This works for me. Your settings.py file seems correct.

    from django.core.mail import EmailMessage
    
    SUBJECT = "Welcome To my site"
    
    
    def send_email(email, password):
        """ send email to new user with temp password"""
    
        msg = EmailMessage(SUBJECT, 'Your temporary login password here. {password}'.format(password=password), to=[email])
        msg.send()
        return True
    
    0 讨论(0)
提交回复
热议问题