0

I've hooked in Gsuite as my SMTP server. It sends out emails and it works very well. However, when using the send_mail function in django, I want to indicate a from address other than the email address that I have hooked into Gsuite, which is admin@mywebsite.com.

    subject = 'Order Confirmation'
    from_email = "jim@gmail.com"
    to_email = ("james@gmail.com",)
    txt_message = "some text"
    html_message = "some other text"

    send_mail(subject,
             txt_message,
             from_email,
             to_email,            
             html_message=html_message,
             fail_silently=False,
             auth_user="admin@mywebsite.com", 
             auth_password="PASSWORD"
             )

When an email is sent out with this code, when I look at the resulting email email in the email client of james@gmail.com, the "from" address is admin@mywebsite.com rather than jim@gmail.com.

Is there a way that I can change this so that the 'from' is jim@gmail.com or at least the 'reply-to' is jim@gmail.com?

Thanks for your help!

Jason Howard
  • 1,464
  • 1
  • 14
  • 43

2 Answers2

2

I think this answers it. Gmail won't allow me to forge a from address, therefore the from address will always be admin@mywebsite.com

to send email with different 'from' email address using gmail smtp server in django

Jason Howard
  • 1,464
  • 1
  • 14
  • 43
1

Gmail doesn't allow you to change the From address when sending email through its servers.

Sources:

change sender address when sending mail through gmail in c#

How to change from-address when using gmail smtp server

https://support.google.com/mail/answer/22370?hl=en

Toni Sredanović
  • 2,280
  • 1
  • 11
  • 13