简体   繁体   中英

Invalid address when sending mail via Django

I am trying to send mail via Django, but have an error: (501, b'5.1.7 Invalid address', '"emea\\\\sss1ss1"') My EMAIL_HOST_USER = r'emea\xss1ss1' . As you can see my user consist \x so I am using r'' . How to fix it, the real EMAIL_settings are correct.

my view.py

def home(request):
    subject  = 'Test mailing'
    message = 'Hello world!!!'
    email_from = settings.EMAIL_HOST_USER
    recipient_list = ['smth@smth.com']
    send_mail(subject,message,email_from,recipient_list)

    return HttpResponse('Test mailing')

well if you want to send an email using Django, first you have to set some variables in settings.py .

settings.py

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.zoho.com'  # for zoho mail service. use smtp.gmail.com for Gmail.
EMAIL_HOST_USER = 'something@something.com'
EMAIL_HOST_PASSWORD = 'something'
DEFAULT_FROM_EMAIL = f'Your Name {EMAIL_HOST_USER}'
EMAIL_PORT = 587
EMAIL_USE_TLS = True

then import send_mail function and settings:
from django.core.mail import send_mail
from your_project import settings

send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, [user_email, ],)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM