Postfix relays via gmail, FROM email is wrong

gmailpostfixsmtp

I recently set up a home-server. And since my ISP quite annoyingly blocks outgoing port 25 I can't setup the SMTP properly. So I set it to relay via gmail(I don't send a lot of mails by this server anyhow, so it's no problem).

Now I have a Magento installation with contactform, if I use that(which uses the localhost SMTP) the from header field is fine with the correct name as well as the correct e-mail address.(note: this is not because of a reply-to header field, the from field really states the correct address)

I also created some e-mail accounts however with which I want to send mail through thunderbird. When I try to send a mail that way the From name is correct, but the e-mail address is the account I use for the relay. Here is an excerpt of my mail.log:

Mar 20 23:11:42 homeserver postfix/smtpd[12203]: connect from xxxx[ip address]
Mar 20 23:11:42 homeserver postfix/smtpd[12203]: setting up TLS connection from xxxx[ip address]
Mar 20 23:11:42 homeserver postfix/smtpd[12203]: Anonymous TLS connection established from xxxx[ip address]: TLSv1 with cipher AES256-SHA (256/256 bits)
Mar 20 23:11:42 homeserver postfix/smtpd[12203]: C5A4936E0228: client=xxxx[ip address], sasl_method=PLAIN, sasl_username=internalemail@domainnameiown.com
Mar 20 23:11:42 homeserver postfix/cleanup[12206]: C5A4936E0228: message-id=<4D867BA1.9080507@domainnameiown.com>
Mar 20 23:11:42 homeserver postfix/qmgr[11844]: C5A4936E0228: from=<internalemail@domainnameiown.com>, size=712, nrcpt=1 (queue active)
Mar 20 23:11:43 homeserver postfix/smtpd[12203]: disconnect from xxxx[ip address]
Mar 20 23:11:43 homeserver postfix/smtp[12207]: C5A4936E0228: to=<example@gmail.com>, relay=smtp.gmail.com[74.125.77.109]:587, delay=1, delays=0.18/0/0.41/0.43, dsn=2.0.0, status=sent (250 2.0.0 OK 1300659106 u45sm1482760eeh.9)
Mar 20 23:11:43 homeserver postfix/qmgr[11844]: C5A4936E0228: removed

So when I would login to example@gmail.com now the from e-mail address is wrong. Is this a setting I got wrong on my homeserver, or can the client set this?

Best Answer

As far as I know, if you use Gmail's SMTP as a relay it rewrites the From address to the Gmail account. Also, any reply-to address is rewritten to the same Gmail account. They've done this for years.

I've run into the same thing when I tried setting Gmail as my relayhost in Postfix. This does not happen with other relays I've tried, so I believe it to be a Gmail thing. I assume Google does this to prevent systems marking the mail as spam since the original From cannot be verified easily.

For individual non-gmail adresses you could configure Gmail by verifying the address. See: http://mail.google.com/support/bin/answer.py?answer=22370

For all adresses in a domain you could configure the domain to use Google Apps, although I've not tried this. Unfortunately this won't help if you relay mail for a number of domains.

See this question for more discussion on this subject: SMTP relay through GMail overrides "from:" address with "[me]@gmail.com"