0
votes

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 i.e. from some other email address.

settings.py

EMAIL_HOST ='smtp.gmail.com' 
EMAIL_PORT = 587
EMAIL_HOST_USER = '[email protected]' 
EMAIL_HOST_PASSWORD = '*********' 
EMAIL_USE_TLS = True

in view:

text="hi this is test mail"
send_mail('Codeville Signup', text.decode(), '[email protected]', ['[email protected]', '[email protected]'], fail_silently=False)

i want to send the mail from "[email protected]" but mail is getting sent by "[email protected]" How can i overcome this problem. And i dont want to change EMAIL_HOST_USER mail address. Guide me through this

1
might be related to this post: stackoverflow.com/questions/13590518/… - Paul Lo
Thank you Paul Lo. it worked. - Wagh

1 Answers

0
votes

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.