I want to non local emails to be relayed via my personal Google account and local to delivered to local user. My configuration is: /etc/postfix/transport

*            smtp:[smtp.gmail.com]:587

and /etc/postfix/main.cf

[root@media postfix]# cat main.cf
# This file contains only the parameters changed from a default install
# see /etc/postfix/main.cf.dist for a commented, fuller version of this file.
transport_maps = hash:/etc/postfix/transport
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_mechanism_filter = plain, login
smtp_sasl_security_options = noanonymous
smtp_use_tls = yes


[smtp.google.com]:587    myuser@gmail.com:mypass

And after I run:

# postmap transport && postmap sasl_passwd
systemctl restart postfix.service

So now my server try to connect to gmail MX (without success but not deliver email localy

Logs from journalctl:

    Jul 06 18:38:01 media postfix/pickup[31431]: 30714960F8: uid=0 from=<root>
    Jul 06 18:38:01 media postfix/cleanup[31641]: 30714960F8: message- id=<20130706163801.30714960F8@media.localdomain>
    Jul 06 18:38:01 media postfix/qmgr[31432]: 30714960F8: from=<root@media.localdomain>, size=436, nrcpt=1 (queue active)
    Jul 06 18:38:01 media postfix/smtp[31643]: connect to smtp.gmail.com[2a00:1450:4008:c01::6c]:587: Network is unreachable
   Jul 06 18:38:01 media postfix/smtp[31643]: 30714960F8: to=<mackowiakp23@gmail.com>, relay=smtp.gmail.com[]:587, delay=0.7, delays=0.03/0.04/0.55/0.07, ...M command))
    Jul 06 18:38:02 media postfix/cleanup[31641]: 0B85D960F9: message-id=<20130706163802.0B85D960F9@media.localdomain>
    Jul 06 18:38:02 media postfix/qmgr[31432]: 0B85D960F9: from=<>, size=2555, nrcpt=1 (queue active)
    Jul 06 18:38:02 media postfix/bounce[31646]: 30714960F8: sender non-delivery notification: 0B85D960F9
    Jul 06 18:38:02 media postfix/qmgr[31432]: 30714960F8: removed
    Jul 06 18:38:02 media postfix/smtp[31643]: connect to smtp.gmail.com[2a00:1450:4008:c01::6d]:587: Network is unreachable
    Jul 06 18:38:02 media postfix/smtp[31643]: 0B85D960F9: to=<root@media.localdomain>, relay=smtp.gmail.com[]:587, delay=0.59, delays=0.02/0.01/0.51/0.06,...M command))
    Jul 06 18:38:02 media postfix/qmgr[31432]: 0B85D960F9: removed
    Jul 06 18:38:40 media auth[31778]: pam_tcb(dovecot:auth): Authentication passed for media from (uid=0)
    Jul 06 18:38:40 media dovecot[1442]: pop3-login: Login: user=<media>, method=PLAIN, rip=, lip=, mpid=31779, secured, session=<VZaXcdrgpADAqAAC>
    Jul 06 18:38:40 media dovecot[1442]: pop3(media): Disconnected: Logged out top=0/0, retr=0/0, del=0/0, size=0
    Jul 06 18:38:58 media postfix/pickup[31431]: CD15D960F8: uid=0 from=<root>
    Jul 06 18:38:58 media postfix/cleanup[31641]: CD15D960F8: message-id=<20130706163858.CD15D960F8@media.localdomain>
    Jul 06 18:38:58 media postfix/qmgr[31432]: CD15D960F8: from=<root@media.localdomain>, size=430, nrcpt=1 (queue active)
    Jul 06 18:38:59 media postfix/smtp[31643]: CD15D960F8: to=<mackowiakp@op.pl>, relay=smtp.gmail.com[]:587, delay=0.63, delays=0.02/0/0.54/0.06, dsn=5.5....M command))
    Jul 06 18:38:59 media postfix/cleanup[31641]: BAB0E960F9: message-id=<20130706163859.BAB0E960F9@media.localdomain>
    Jul 06 18:38:59 media postfix/qmgr[31432]: BAB0E960F9: from=<>, size=2541, nrcpt=1 (queue active)
    Jul 06 18:38:59 media postfix/bounce[31646]: CD15D960F8: sender non-delivery notification: BAB0E960F9
    Jul 06 18:38:59 media postfix/qmgr[31432]: CD15D960F8: removed
Jul 06 18:39:00 media postfix/smtp[31643]: BAB0E960F9: to=<root@media.localdomain>, relay=smtp.gmail.com[]:587, delay=0.66, delays=0.02/0.01/0.56/0.07,...M command))
    Jul 06 18:39:00 media postfix/qmgr[31432]: BAB0E960F9: removed

Any help to make it working?

  • Is that asterisk really in your /etc/postfix/transport, or is it just something that got added inadvertantly to your question? – user Jul 7 '13 at 8:14

You have to enable TLS in Postfix's SMTP client, since Google requires it. This is indicated by them in the message Must issue a STARTTLS command.

In /etc/postfix/main.cf, you want something like this:

smtp_tls_policy_maps = hash:/etc/postfix/tls_policy

and then in /etc/postfix/tls_policy:

[smtp.gmail.com]:587 encrypt

The left hand side in tls_policy must appear exactly the same as your relayhost entry in main.cf.

Remember to run postmap on /etc/postfix/tls_policy after creating or changing it as required.

You can find more details in Postfix's TLS documentation.

Refer these links




This is the procedure I use for this:

sudo apt-get install postfix.

If it asks what sort of mail server you are installed, choose no configuration (the first option)

sudo nano /etc/postfix/main.cf

and paste this in

# See /usr/share/postfix/main.cf.dist for a commented, more complete version

# Debian specific:  Specifying a file name will cause the first
# line of that file to be used as the name.  The Debian default
# is /etc/mailname.
#myorigin = /etc/mailname
# listen on localhost only
inet_interfaces =

smtpd_banner = $myhostname ESMTP $mail_name

biff = no

# appending .domain is the MUA's job.
append_dot_mydomain = no

#Uncomment the next line to generate "delayed mail" warnings
#delay_warning_time = 4h

relayhost = [smtp.gmail.com]:587
smtp_use_tls = yes
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous

Save the file, Now we create the file with the username and password in

sudo nano /etc/postfix/sasl_passwd

and paste in the following making the required replacements

[smtp.gmail.com]:587    user.name@gmail.com:password

Save it, and at the command prompt

sudo postmap /etc/postfix/sasl_passwd


chmod 600 /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db


sudo service postfix restart

Note that once you’ve successfully tested the email system, you can remove / obfuscate the password in sasl_passwd.

Test it with you application. If you have trouble, check /var/log/mail.log You can apt-get install mail-utils to have it install a mail program. you can then test with

echo “this is a test” | mailx -s “This is the subject” destination@example.com




to make an /etc/aliases.db file. If you don’t it will log a lot of errors about it to /var/log/mail.err If you get SASL errors (postfix) Check the hostname is in /etc/hosts and /etc/hostname If postfix complains about not being able to relay for a given host / ip address (postfix) Add this to /etc/postfix/main.cf

mynetworks =

This will allow anyone with a address to connect, obviously you should bolt this down as much as possible, either by restricting the network, and / or using any firewall or security policy available to you

  • OK. THX. But what You use to create/obtain /etc/ssl/certs/Equifax_Secure_CA.pem certificate? – mackowiakp Jul 7 '13 at 14:32
  • My mistake, You shouldn't need that line. I've edited the post above to reflect this – GeoSword Jul 16 '13 at 20:16
  • I got info: <test.user@domain.com>: host smtp.gmail.com[] said: 530-5.5.1 Authentication Required. Learn more at 530 5.5.1 support.google.com/mail/bin/answer.py?answer=14257 fc7sm2465531bkc.3 - gsmtp (in reply to MAIL FROM command) - so in such configuration MAIL FROM must be included in relay definition. How can I do it? – mackowiakp Jul 17 '13 at 20:45
  • Oh s*&^*t ! In /etc/postfix/sasl_passwd was [smtp.google.com]:587 instead [smtp.gmail.com]:587. Sometimes is terribly difficult to find out such simple error. THX! WORKS! – mackowiakp Jul 18 '13 at 17:16

Firstly, make sure to check first Google's authentication method:


If the page is not available for your account, then the the domain administrator disabled this settings for all users (default).

When you whitelist your IP/range in Relay SMTP in google admin, you can send emails with this settings

relayhost = [smtp-relay.gmail.com]:587
smtp_use_tls = yes
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_sasl_mechanism_filter = login, plain
smtp_tls_CApath = /etc/ssl/certs
smtp_sasl_tls_security_options = noanonymous

However, when Allow less secure apps: OFF I was always getting these messages:

(SASL authentication failed; server smtp-relay.gmail.com[] said: 534-5.7.14
... Please log in via your web browser and?534-5.7.14 then try again.?534-5.7.14
Learn more at?534 5.7.14  https://support.google.com/mail/answer/78754 g133sm1077601qkb.1 - gsmtp)

but messages were still delivered (which is a bit strange), although it took a bit longer to get message to its recipient.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.