Setup Postfix on Ubuntu 16.04 Localhost and Use Gmail SMTP

READ: https://devanswers.co/configure-postfix-to-use-gmail-smtp-on-ubuntu-16-04-digitalocean-droplet/

Prerequisites
If your Gmail account uses 2-Step Verification, you must create an application specific password.

If you’re not using 2-Step Verification, please ensure that your Gmail account is configured to allow less secures apps.

Remove sendmail

1. Install Postfix

Let’s update the package database first. On the first Postfix configuration screen, select OK by pressing TAB and ENTER. Select Internet Site and press ENTER. System mail name should be your domain name eg. example.com, press ENTER.
My mail name is teddy@teddy.localdomain
<NOTE>
PROBABLY THESE BELOW COMMAND NOT NEEDED:
I also need to install php-mail and php7.2-mail

modify php ini IN

OR FOR APACHE2 WEB SERVER

UNCOMMENT ‘sendmail_path’ THEN CHANGE TO

modify

like this:

Restart services

OR FOR APACHE2 WEB SERVER

</NOTE>

Configure Postfix
Edit the Postfix configuration file.

Add the following to the end of the file.

Save file and exit.

Create Password and DB Files
Create the sasl_passwd file which will store our credentials.

Insert the following:

SORRY, ONLY ADMIN CAN SHOW THIS!
Replace username and password with your own. Save file and exit. (Press CTRL + X, press Y and then press ENTER)

Create a hash database file for Postfix with the postmap command.

There should now be a file called sasl_passwd.db in the /etc/postfix/ directory.

For added security, we will only allow root user to read and write to sasl_passwd and sasl_passwd.db

Sign Certificate
Now we are going to create the certificate.

There should now be a certificate file called cacert.pem in /etc/postfix

Send a Test Mail
We’ll now send a test email message. Make sure to replace test@example.com with your own email address.

Don’t forget to check your spam folder.

If you still haven’t received any mail, check the mail error log.

NOTE:
TO USE GMAIL SMPT, YOU NEED TO ACTIVATE (SET IT ON) ‘Less Secure app’ ON YOUR GMAIL ACCOUNT. LOGIN TO YOUR GMAIL THEN OPEN THIS LINK: https://www.google.com/settings/u/2/security/lesssecureapps
IT’D REDIRECT YOU THE ‘Less Secure app’ SETTING.

Leave a Reply

Your email address will not be published. Required fields are marked *