Use SMTP Email Service From Google
If you are in need of email services and don't have your own mail server, one of the options you can use as a G Suite customer is Google's SMTP mail service.
The following instructions use Postfix to be the localhost mail delivery daemon:
Once you have enabled 2FA for your G Suite account, find the latest instructions from Google's help section on creating App Passwords on your account.
sendmail [email protected]
From: [email protected]
Subject: Test mail
This is a test email
.
The following instructions use Postfix to be the localhost mail delivery daemon:
1. Install Postfix
sudo apt install postfix2. Configure Gmail Authentication
The best option is to enable Two-Factor Authentication (2FA) on your G Suite account so that you can create App Passwords. These passwords are used in place of your regular G Suite password when configuring Postfix as a relay mail server.Once you have enabled 2FA for your G Suite account, find the latest instructions from Google's help section on creating App Passwords on your account.
3. Add G Suite User and Password to Postfix
Usernames and passwords are stored in the /etc/postfix/sasl/sasl_passwd file:- Open or create /etc/postfix/sasl/sasl_passwd and add the SMTP host, username, and password accordingly for G Suite:
- Create the sasl_passwd.db file for Postfix
- Secure the sasl_passwd and sasl_passwd.db files
[smtp.gmail.com]:587 [email protected]:password
sudo postmap /etc/postfix/sasl/sasl_passwd
sudo chown root:root /etc/postfix/sasl/sasl_passwd
sudo chown root:root /etc/postfix/sasl/sasl_passwd.db
sudo chmod 0600 /etc/postfix/sasl/sasl_passwd
sudo chmod 0600 /etc/postfix/sasl/sasl_passwd.db
4. Configure Postfix to be a Relay Server
- Modify /etc/postfix/main.cf to use Google's SMTP server
- At the end of the file, add the following parameters to enable authentication
- Restart Postfix service
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
sudo systemctl restart postfix
5. Test Postfix
Use Postfix’s sendmail implementation to send a test email:sendmail [email protected]
From: [email protected]
Subject: Test mail
This is a test email
.
Comments
Post a Comment