Postfix relays via gmail, FROM email is wrong

10,039

Solution 1

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"

Solution 2

Postfix has a feature called "smtp_generic_maps"

You can create a generic maps file with

postmap /path/to/map/file

The map file looks like this

user@localhost user@remotehost

Then add

smtp_generic_maps = hash:/etc/postfix/generic

into main.cf

Mails from user@localhost will now be delivered as user@remotehost using SMTP

Share:
10,039

Related videos on Youtube

teuneboon
Author by

teuneboon

Experienced developer(for my age at least), interested in Java, PHP and javascript and always looking into new techniques.

Updated on September 17, 2022

Comments

  • teuneboon
    teuneboon almost 2 years

    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, [email protected]
    Mar 20 23:11:42 homeserver postfix/cleanup[12206]: C5A4936E0228: message-id=<[email protected]>
    Mar 20 23:11:42 homeserver postfix/qmgr[11844]: C5A4936E0228: from=<[email protected]>, 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=<[email protected]>, 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 [email protected] now the from e-mail address is wrong. Is this a setting I got wrong on my homeserver, or can the client set this?

    • Jeremy Bouse
      Jeremy Bouse over 13 years
      How exactly is the from e-mail address wrong? I can't tell from what you've supplied so far.
    • teuneboon
      teuneboon over 13 years
      @Jeremy Bouse: well, say I use the account [email protected] as a relay. And two.com is on my server as a domain. When I send from my server as Info<[email protected]> now. The client recieves it as Info<[email protected]>
  • user53864
    user53864 over 10 years
    Thanks! this helped me. When I replaced my gmail relay account with another, it was still sending from previous gmail account. I first issued postmap and restarted postfix and then it worked!.