0

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 = '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

Wagh
  • 4,202
  • 5
  • 39
  • 62
  • 1
    might be related to this post: http://stackoverflow.com/questions/13590518/emailbackend-for-sending-email-through-multiple-smtp-in-django – Paul Lo Feb 02 '15 at 13:01

1 Answers1

0

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.

Community
  • 1
  • 1
Wagh
  • 4,202
  • 5
  • 39
  • 62