2
votes

I am using gmail smtp in my django website. I have a contact form where user put email and message then I send a mail to the admin with :

   email = EmailMessage('email subject', 'email message', settings.EMAIL_HOST_USER,
                        ['[email protected]'],
                          headers = {'Reply-To': '[email protected]',
                               'Sender': '[email protected]','from': '[email protected]','Return-Path': '[email protected]'})
   email.send(fail_silently=False)

email is sent/received correctly but when admin client select reply in gmail, it always reply to the settings.EMAIL_HOST_USER and not the user address. On the email original header the From and Return-path are set with the setting.EMAIL_HOST_USER

3
Are you saying that you are sending the message through gmail's smtp server smtp.gmail.com? And, when the recipient receives the message, the sender's address (and the reply to address) are showing as the gmail address associated with the gmail account that you are using to send the message through, instead of the sender address that you are specifying in your code?mti2935
Yes it is, some part of the header are ignored by smtp.gmail.com. I guess that it must be a security feature. I currently looking to use exim4 on my server instead of gmailuser1946989

3 Answers

5
votes

Google violates the RFPs defining the expected operation of an SMTP server, rewriting the headers. This may be the root cause of your problem: http://lee-phillips.org/gmailRewriting/

1
votes

If you use smtp.gmail.com to send a message, and the sender's email address is not [email protected], then Gmail will rewrite the headers and set the from address to [email protected]. See http://lifehacker.com/111166/how-to-use-gmail-as-your-smtp-server for more info, and for a possible solution.

0
votes

I have the same problem for a year, due to the Gmail restriction.

But today I retry and it works, it seems that Google changed its policy.

# settings.py
....
DEFAULT_FROM_EMAIL = 'Infoma Admin<[email protected]>'

enter image description here

Django 2.1.7