2

I'm using flask_mail configured to use gmail smtp server. It sends mail fine except all mail looks it is coming from the gmail smtp user name and NOT from what I set in the 'sender' argument of the mail.send_message(...) command. When I look at the source of the generate emails I see 2 different FROM addresses. How can I change this to show my desired 'from'?

    mail.send_message(subject='subject line',
                      sender='my_from_email@gmail.com', 
                      recipients=['my_to_email@gmail.com'],
                      bcc=['bcc_email@gmail.com'],
                      reply_to='my_from_email@gmail.com')

snip-it of header looks like...

...
From: my_smtp_user_name@gmail.com
X-Google-Original-From: my_from_email@gmail.com
Content-Type: multipart/mixed; boundary="===============8405132704319078372=="
MIME-Version: 1.0
...
dreed47
  • 51
  • 4

1 Answers1

2

TLDR: gmail smtp server is preventing email spoofing.

see: https://github.com/gophish/gophish/issues/1311

to fix:

log into your my_smtp_user_name@gmail.com account in Gmail and set up sending email as my_from_email@gmail.com there first. Once your account is allowed and authenticated as allowed to send email as your other account your headers should stop being re-writen.

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

user3616725
  • 3,485
  • 1
  • 18
  • 27