Difference between revisions of "Sending email via Gmail relay through postfix"
m |
m |
||
(9 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
[[Main Page|Home]] > [[CentOS]] > [[CentOS 6.x]] > [[Postfix server configuration]] > [[Sending email via Gmail relay through postfix]] | |||
'''There is newer article at [[CentOS 8.x postfix send email through relay or smarthost with smtp authentication]]''' | |||
'''Avoid use of less secure apps. Better option is to enable 2-step verification. Then create app passwords for apps that do not support 2-step verification / OAUTH etc.'''. See | |||
Also note that Gmail is likely to stop support for less secure apps very soon (See https://support.excelmicro.com/index.php?/News/NewsItem/View/374/g-suite-switch-to-g-suite-apps-that-use-secure-oauth-access-as-password-based-access-will-no-longer-be-supported ). '''Most of emails sent via gmail using this technique neither seem to get delivered neither bounce back!!!'''. | |||
To send email via Gmail relay through postfix use: | To send email via Gmail relay through postfix use: | ||
Line 7: | Line 13: | ||
##In "Google Account Settings" go to Sign-in and Security. | ##In "Google Account Settings" go to Sign-in and Security. | ||
##In Sign-in and security change "Allow less secure apps:" to ON | ##In Sign-in and security change "Allow less secure apps:" to ON | ||
# yum -y install | # yum -y install cyrus-sasl cyrus-sasl-plain cyrus-sasl-lib postfix mailx | ||
#'''Note that without cyrus-sasl and related packages error no worthy mechanisms found would be received while authenticating to Gmail via postfix'''. Refer https://serverfault.com/questions/325955/no-worthy-mechs-found-when-trying-to-relay-email-to-gmail-using-postfix | |||
# Set at least following in /etc/postfix/main.cf for mail system to work properly: | |||
#:<pre> | |||
#:: myhostname | |||
#:: mydomain | |||
#:: myorigin | |||
#:: inet_interfaces = all | |||
#:: inet_protocols = ipv4 | |||
#:</pre> | |||
#edit /etc/postfix/sasl_passwd and put something like | #edit /etc/postfix/sasl_passwd and put something like | ||
#:<pre> | #:<pre> | ||
#::smtp.gmail.com <gmail-email-address>:<gmail-password> | #::smtp.gmail.com <gmail-email-address>:<gmail-password> | ||
#:</pre> | #:</pre> | ||
#cd /etc/postfix | # Create hash postmap of sasl_password using: | ||
#chmod 600 sasl_passwd | #:<pre> | ||
#postmap hash:/etc/postfix/sasl_passwd | #:: cd /etc/postfix | ||
#:: chmod 600 sasl_passwd | |||
#:: postmap hash:/etc/postfix/sasl_passwd | |||
#:</pre> | |||
#edit /etc/postfix/main.cf and after relayhost comment lines insert | #edit /etc/postfix/main.cf and after relayhost comment lines insert | ||
#:<pre> | #:<pre> | ||
Line 24: | Line 42: | ||
#:</pre> | #:</pre> | ||
#service postfix restart | #service postfix restart | ||
#echo "Test email using postfix" | mail -s "Gmail relay test" saurabh@ | #echo "Test email using postfix" | mail -s "Gmail relay test" saurabh@example.com | ||
#Look for successful email being sent or errors logs using: | #Look for successful email being sent or errors logs using: | ||
#:<pre> | #:<pre> | ||
Line 37: | Line 55: | ||
[[Main Page|Home]] > [[CentOS]] > [[CentOS 6.x]] > [[Postfix server configuration]] > [[Sending email via Gmail relay through postfix]] |
Latest revision as of 10:40, 14 July 2022
Home > CentOS > CentOS 6.x > Postfix server configuration > Sending email via Gmail relay through postfix
There is newer article at CentOS 8.x postfix send email through relay or smarthost with smtp authentication
Avoid use of less secure apps. Better option is to enable 2-step verification. Then create app passwords for apps that do not support 2-step verification / OAUTH etc.. See
Also note that Gmail is likely to stop support for less secure apps very soon (See https://support.excelmicro.com/index.php?/News/NewsItem/View/374/g-suite-switch-to-g-suite-apps-that-use-secure-oauth-access-as-password-based-access-will-no-longer-be-supported ). Most of emails sent via gmail using this technique neither seem to get delivered neither bounce back!!!.
To send email via Gmail relay through postfix use:
- Configure gmail to use less secure apps using:
- Login into Gmail account and go to Settings -> Accounts -> Google Account Settings
- In "Google Account Settings" go to Sign-in and Security.
- In Sign-in and security change "Allow less secure apps:" to ON
- yum -y install cyrus-sasl cyrus-sasl-plain cyrus-sasl-lib postfix mailx
- Note that without cyrus-sasl and related packages error no worthy mechanisms found would be received while authenticating to Gmail via postfix. Refer https://serverfault.com/questions/325955/no-worthy-mechs-found-when-trying-to-relay-email-to-gmail-using-postfix
- Set at least following in /etc/postfix/main.cf for mail system to work properly:
- myhostname
- mydomain
- myorigin
- inet_interfaces = all
- inet_protocols = ipv4
- edit /etc/postfix/sasl_passwd and put something like
- smtp.gmail.com <gmail-email-address>:<gmail-password>
- Create hash postmap of sasl_password using:
- cd /etc/postfix
- chmod 600 sasl_passwd
- postmap hash:/etc/postfix/sasl_passwd
- edit /etc/postfix/main.cf and after relayhost comment lines insert
- smtp_sasl_auth_enable = yes
- smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
- smtp_sasl_security_options =
- smtp_tls_security_level = may
- relayhost = smtp.gmail.com:587
- service postfix restart
- echo "Test email using postfix" | mail -s "Gmail relay test" saurabh@example.com
- Look for successful email being sent or errors logs using:
- mailq
- tail -50 /var/log/maillog
- Logging into above configured "Less secure Gmail" account via browser also helps
To troubleshoot look at /var/log/maillog. In log lines look at value of ctladdr such as 'ctladdr=saurabh (501/501)'. Then look at /var/mail/saurabh or login as user saurabh and use 'mail' command to see error message sent by Gmail server.
Home > CentOS > CentOS 6.x > Postfix server configuration > Sending email via Gmail relay through postfix