How to Relay Emails to Gmail: Difference between revisions
Jump to navigation
Jump to search
Jgutierrez6 (talk | contribs) (Created page with "== Introduction == This tutorial applies to RHEL 8 based operating systems (CentOS, Rocky Linux) Two machines that send emails are: *vav.combpio.ucsf.edu *bksmailman.compbio....") |
Jgutierrez6 (talk | contribs) mNo edit summary |
||
(6 intermediate revisions by the same user not shown) | |||
Line 17: | Line 17: | ||
systemctl disbale sendmail --now (Disable package) | systemctl disbale sendmail --now (Disable package) | ||
</source> | </source> | ||
# Enable smtp in firewall | |||
#* <source> | |||
firewall-cmd --permanent --add-service=smtp | |||
</source> | |||
# Install Postfix and other dependencies | |||
#* <source> | |||
yum install postfix mailx cyrus-sasl cyrus-sasl-plain -y | |||
</source> | |||
# Configure Postfix | |||
#* <source> | |||
vim /etc/postfix/main.cf | |||
//Copy these lines and paste it at the bottom of the main.cf file | |||
relayhost = [smtp.gmail.com]:587 | |||
smtp_use_tls = yes | |||
smtp_sasl_auth_enable = yes | |||
smtp_sasl_security_options = noanonymous | |||
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd | |||
smtp_tls_security_level = encrypt | |||
smtp_tls_CAfile = /etc/ssl/certs/ca-bundle.crt | |||
</source> | |||
# Set up authentication file for gmail | |||
#* <source> | |||
vim /etc/postfix/sasl_passwd | |||
//Paste this line and replace | |||
[smtp.gmail.com]:587 docking.email@gmail.com:<gmail_app_password> | |||
</source> | |||
# Create Gmail App Password For Authentication | |||
#* Log in to gmail account | |||
#* Click top right account button | |||
#* Click 'Manage Google Account' | |||
#* On the left, click the 'Security' tab | |||
#* Enable '2-step Verification' | |||
#* Now back to security tab and click 'App Passwords' | |||
#* Generate App Password | |||
#* Click 'Other' for the category input | |||
#* Copy the generated token and save somewhere | |||
# Once you have token, replace <gmail_app_password> in sasl_passwd file with the token and save the file | |||
# Update the password database | |||
#* <source> | |||
postmap /etc/postfix/sasl_passwd | |||
chown root:root /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db | |||
chmod 0600 /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db | |||
systemctl restart postfix.service | |||
systemctl status postfix | |||
</source> | |||
# Verify that it works | |||
#* <source> | |||
echo "This is the body of the email" | mail -s "This is the subject line" <your_email> | |||
</source> | |||
# If it works you're done. If it doesn't check the reference tutorial for troubleshooting. |
Latest revision as of 22:43, 1 September 2022
Introduction
This tutorial applies to RHEL 8 based operating systems (CentOS, Rocky Linux)
Two machines that send emails are:
- vav.combpio.ucsf.edu
- bksmailman.compbio.ucsf.edu
Relaying emails through gmail will make it more secure and trustworthy.
Instructions
- Create a gmail account OR Ask Khanh for docking.email@gmail.com for credentials.
- Disable pre-installed 'sendmail' package
rpm -q sendmail (Check for package) systemctl disbale sendmail --now (Disable package)
- Enable smtp in firewall
firewall-cmd --permanent --add-service=smtp
- Install Postfix and other dependencies
yum install postfix mailx cyrus-sasl cyrus-sasl-plain -y
- Configure Postfix
vim /etc/postfix/main.cf //Copy these lines and paste it at the bottom of the main.cf file relayhost = [smtp.gmail.com]:587 smtp_use_tls = yes smtp_sasl_auth_enable = yes smtp_sasl_security_options = noanonymous smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd smtp_tls_security_level = encrypt smtp_tls_CAfile = /etc/ssl/certs/ca-bundle.crt
- Set up authentication file for gmail
vim /etc/postfix/sasl_passwd //Paste this line and replace [smtp.gmail.com]:587 docking.email@gmail.com:<gmail_app_password>
- Create Gmail App Password For Authentication
- Log in to gmail account
- Click top right account button
- Click 'Manage Google Account'
- On the left, click the 'Security' tab
- Enable '2-step Verification'
- Now back to security tab and click 'App Passwords'
- Generate App Password
- Click 'Other' for the category input
- Copy the generated token and save somewhere
- Once you have token, replace <gmail_app_password> in sasl_passwd file with the token and save the file
- Update the password database
postmap /etc/postfix/sasl_passwd chown root:root /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db chmod 0600 /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db systemctl restart postfix.service systemctl status postfix
- Verify that it works
echo "This is the body of the email" | mail -s "This is the subject line" <your_email>
- If it works you're done. If it doesn't check the reference tutorial for troubleshooting.