简体   繁体   中英

in send mail from is not working in django

i am trying to send the mail in django. mail is going properly but mail is going by EMAIL_HOST_USER. Want to send the mail using from ie from some other email address.

settings.py

EMAIL_HOST ='smtp.gmail.com' 
EMAIL_PORT = 587
EMAIL_HOST_USER = 'you@everycrave.me' 
EMAIL_HOST_PASSWORD = '*********' 
EMAIL_USE_TLS = True

in view:

text="hi this is test mail"
send_mail('Codeville Signup', text.decode(), 'gaurav@everycrave.me', ['manish@everycrave.me', 'jagat@everycrave.me'], fail_silently=False)

i want to send the mail from "gaurav@everycrave.me" but mail is getting sent by "you@everycrave.me" How can i overcome this problem. And i dont want to change EMAIL_HOST_USER mail address. Guide me through this

You can refer EmailBackend for sending email through multiple SMTP in Django this question or

in your view you have to write this code, from where you are sending the email.

from django.core.mail import get_connection, send_mail
from django.core.mail.message import EmailMessage
#TODO: Insert clever settings mechanism
my_host = 'smtp.gmail.com'
my_port = 587
my_username = 'your email address'
my_password = 'password'
my_use_tls = True
connection = get_connection(host=my_host, 
                            port=my_port, 
                            username=my_username, 
                            password=my_password, 
                            user_tls=my_use_tls) 

EmailMessage('Test subject', 'test message', 'from_email', ['to'], connection = connection).send(fail_silently=False)

Check this.

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