I have configured Postfix to Send Mail Using Gmail. I have modified the file /etc/postfix/main.cf


myhostname = fqdn.peris.app
mydestination = $myhostname, peris.app, localhost, localhost.localdomain, localhost
relayhost = [smtp.gmail.com]:587
# Enable SASL authentication
smtp_sasl_auth_enable = yes
# Disallow methods that allow anonymous authentication
smtp_sasl_security_options = noanonymous
# Location of sasl_passwd
smtp_sasl_password_maps = hash:/etc/postfix/sasl/sasl_passwd
# Enable STARTTLS encryption
smtp_tls_security_level = encrypt
# Location of CA certificates
smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt

I also Log in to my gmail account, then click on Manage your account access and security settings. Scroll down to “Password & sign-in method” and click 2-Step Verification, Ensuring that 2-Step Verification is enabled and generating a password that I use in the file



[smtp.gmail.com]:587 [email protected]:xkltgnxoxzmocpce

Then I test it with:

sendmail [email protected]
From: [email protected]
Subject: Test mail
This is a test email

and what I receive in the [email protected] is a mail from [email protected] and I thought I should received directly from my domain, [email protected]

2 Answers 2


If you received your test emails from [email protected], it's a good sign: it means you have correctly configured your postfix!

It seems you are unhappy that Google rewrites the sender address. The explanation is that your Gmail account can only send emails from addresses it knows are yours, to avoid spoofing.

What about the option to verify a non-google email address thus enabling sending emails from that address from within your Gmail account? Those emails are indeed going to be sent from your Gmail account, but not from Google's servers: as a matter of fact, when you add an address from Settings->Accounts, you are asked to provide the SMTP server details. The reason is, those messages would likely end up being marked as spam if sent from Google's servers.

What you could do is add your domain to Gsuite: that way you are going to be able to both send and receive emails using Google's servers. You'll receive instructions on how to set SPF records and those emails are not likely going to be considered spam. Note that Gsuite has a fixed monthly cost, but includes a number of additional services you might or might not need.

Another option that I feel like recommending is resorting to a SMTP relay service, such as Amazon SES, SendGrid, MailGun, Mailchannels or SparkPost. Each has its own specific advantages and you can try most for free, some having very generous free allowances.


I believe Gmail automatically overwrites the "From: " line when used as a relay, like explained here, and here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .