How to mask local host name when sending emails using postfix through gmail

Sergey asked:

I have a few scripts I’m running that are sending an email. I wanted to configure everything to be able to use simple mail() functions and have emails coming from my gmail account, without exposing my server. However, all of the guides I’ve seen end up with postfix adding a line exposing the hostname of the local server and my public IP address.

How can I configure postfix so that it looks like the email was sent directly from gmail, without relaying through another host? And I’d like to configure it on postfix end, rather than having to rewrite the script to go to gmail directly. mail() is just so convenient!

My answer:

You can’t.

To “hide” your local server you’ll have to send the mail directly to Gmail on authenticated port 587, bypassing the local Postfix server.

View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.