Gmail blocks emails from Postfix client on Linux
August 23, 2021 Leave a comment
Problem:
I want to send email notification to my Gmail account from Linux server using Postfix client. Mails are not received and /var/log/maillog
is full of the following error messages:
Aug 18 17:24:29 rac1 postfix/smtp[17580]: connect to gmail-smtp-in.l.google.com[74.125.69.27]:25: Connection timed out Aug 18 17:24:29 rac1 postfix/smtp[17580]: connect to gmail-smtp-in.l.google.com[2607:f8b0:4001:c0d::1a]:25: Network is unreachable Aug 18 17:24:59 rac1 postfix/smtp[17580]: connect to alt1.gmail-smtp-in.l.google.com[173.194.77.27]:25: Connection timed out Aug 18 17:25:29 rac1 postfix/smtp[17580]: connect to alt2.gmail-smtp-in.l.google.com[173.194.219.27]:25: Connection timed out
Solution:
Configure Postfix and Gmail account accordingly.
1. Confirm that the myhostname
parameter is configured with your server’s FQDN:
# grep ^myhostname /etc/postfix/main.cf myhostname = rac1.example.com
2. Generate an App Password for Postfix:
Click on App passwords -> Select app dropdown -> choose Other (custom name) -> Enter “Postfix” -> click GENERATE.
Postfix app password is generated in yellow box, copy and save it (generated_password_goes_here will be changed by this value).
3. Fill SMTP Host, username, and password in /etc/postfix/sasl_passwd
# cat /etc/postfix/sasl_passwd smtp.gmail.com your_username@gmail.com:generated_password_goes_here
4. Create the hash db file
# postmap /etc/postfix/sasl_passwd
5. Configure the Postfix Relay Server:
# grep ^relayhost /etc/postfix/main.cf relayhost = [smtp.gmail.com]:587
6. To enable authentication, add the following parameters in /etc/postfix/main.cf
smtp_sasl_auth_enable = yes smtpd_tls_auth_only = yes smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd smtp_sasl_security_options = noanonymous smtp_tls_security_level = encrypt
7. Reload Postfix service:
# systemctl reload postfix
8. For sending test email, I use Flashgrid tool:
[root@rac1 ~]# flashgrid-node test-alerts FlashGrid 21.2.24.58935 #bb6005e9d66650d1996184c38d2fb8a2a78420a8 License: Active, Marketplace Licensee: Flashgrid Inc. Support plan: 24x7 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Test alerts were sent
The alert is received now:
