{"id":4541,"date":"2019-08-15T03:41:06","date_gmt":"2019-08-15T03:41:06","guid":{"rendered":"http:\/\/myprojects.advchaweb.com\/?p=4541"},"modified":"2023-06-01T03:56:02","modified_gmt":"2023-06-01T03:56:02","slug":"setup-postfix-on-ubuntu-16-04-localhost-and-use-gmail-smtp","status":"publish","type":"post","link":"https:\/\/myprojects.advchaweb.com\/index.php\/2019\/08\/15\/setup-postfix-on-ubuntu-16-04-localhost-and-use-gmail-smtp\/","title":{"rendered":"Setup Postfix on Ubuntu 16.04 Localhost and Use Gmail SMTP"},"content":{"rendered":"<p>READ: https:\/\/devanswers.co\/configure-postfix-to-use-gmail-smtp-on-ubuntu-16-04-digitalocean-droplet\/<\/p>\n<p>Prerequisites<br \/>\nIf your Gmail account uses\u00a02-Step Verification, you must\u00a0create an application specific password.<\/p>\n<p>If you\u2019re\u00a0not\u00a0using 2-Step Verification, please ensure that your Gmail account is configured to\u00a0allow less secures apps.<\/p>\n<p>Remove sendmail<\/p>\n<pre class=\"lang:default decode:true\">sudo apt-get remove sendmail<\/pre>\n<p>1. Install Postfix<\/p>\n<pre class=\"lang:default decode:true\">sudo apt-get update\r\nsudo apt install -y postfix mailutils<\/pre>\n<p>Let\u2019s 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\u00a0should be your domain name eg.\u00a0example.com, press\u00a0ENTER.<br \/>\nMy mail name is teddy@teddy.localdomain<br \/>\n&lt;NOTE&gt;<br \/>\nPROBABLY THESE BELOW COMMAND NOT NEEDED:<br \/>\nI also need to install php-mail and php7.2-mail<\/p>\n<pre class=\"lang:default decode:true\">sudo apt install php-mail and php7.2-mail<\/pre>\n<p>modify php ini IN<\/p>\n<pre class=\"lang:default decode:true \">sudo gedit \/etc\/php\/7.2\/fpm\/php.ini<\/pre>\n<p>OR FOR APACHE2 WEB SERVER<\/p>\n<pre class=\"lang:default decode:true \">sudo gedit \/etc\/php\/7.2\/apache2\/php.ini<\/pre>\n<p>UNCOMMENT &#8216;sendmail_path&#8217; THEN CHANGE TO<\/p>\n<pre class=\"lang:default decode:true\">sendmail_path = \/usr\/sbin\/sendmail -t -i<\/pre>\n<p>modify<\/p>\n<pre class=\"lang:default decode:true\">sudo gedit \/etc\/hosts<\/pre>\n<p>like this:<\/p>\n<pre class=\"lang:default decode:true \">127.0.0.1\tteddy.localdomain teddy localhost\r\n#127.0.0.1\tlocalhost\r\n#127.0.1.1\tteddy<\/pre>\n<p>Restart services<\/p>\n<pre class=\"lang:default decode:true \">sudo service php7.2-fpm restart\r\nsudo service nginx restart\r\n<\/pre>\n<p>OR FOR APACHE2 WEB SERVER<\/p>\n<pre class=\"lang:default decode:true \">sudo service apache2 start<\/pre>\n<p>&lt;\/NOTE&gt;<\/p>\n<p>Configure Postfix<br \/>\nEdit the Postfix configuration file.<\/p>\n<pre class=\"lang:default decode:true\">sudo gedit \/etc\/postfix\/main.cf<\/pre>\n<p>Add the following to the end of the file.<\/p>\n<pre class=\"lang:default decode:true \">relayhost = [smtp.gmail.com]:587\r\nsmtp_sasl_auth_enable = yes\r\nsmtp_sasl_password_maps = hash:\/etc\/postfix\/sasl_passwd\r\nsmtp_sasl_security_options = noanonymous\r\nsmtp_tls_CAfile = \/etc\/postfix\/cacert.pem\r\nsmtp_use_tls = yes<\/pre>\n<p>Save file and exit.<\/p>\n<p>Create Password and DB Files<br \/>\nCreate the\u00a0sasl_passwd\u00a0file which will store our credentials.<\/p>\n<pre class=\"lang:default decode:true\">sudo gedit \/etc\/postfix\/sasl_passwd<\/pre>\n<p>Insert the following:<\/p>\n<pre class=\"lang:default decode:true\">[smtp.gmail.com]:587 username@gmail.com:password<\/pre>\n<span class=\"rcp-restricted-content-message\">SORRY, ONLY ADMIN CAN SHOW THIS!<\/span><br \/>\nReplace username and password with your own. Save file and exit. (Press\u00a0CTRL\u00a0+\u00a0X, press\u00a0Y\u00a0and then press\u00a0ENTER)<\/p>\n<p>Create a hash database file for Postfix with the\u00a0postmap\u00a0command.<\/p>\n<pre class=\"lang:default decode:true \">sudo postmap \/etc\/postfix\/sasl_passwd<\/pre>\n<p>There should now be a file called\u00a0sasl_passwd.db\u00a0in the\u00a0\/etc\/postfix\/\u00a0directory.<\/p>\n<p>For added security, we will only allow\u00a0root\u00a0user to read and write to\u00a0sasl_passwd\u00a0and\u00a0sasl_passwd.db<\/p>\n<pre class=\"lang:default decode:true \">sudo chown root:root \/etc\/postfix\/sasl_passwd \/etc\/postfix\/sasl_passwd.db\r\nsudo chmod 0600 \/etc\/postfix\/sasl_passwd \/etc\/postfix\/sasl_passwd.db<\/pre>\n<p>Sign Certificate<br \/>\nNow we are going to create the certificate.<\/p>\n<pre class=\"lang:default decode:true \">cat \/etc\/ssl\/certs\/thawte_Primary_Root_CA.pem | sudo tee -a \/etc\/postfix\/cacert.pem<\/pre>\n<p>There should now be a certificate file called\u00a0cacert.pem\u00a0in\u00a0\/etc\/postfix<\/p>\n<p>Send a Test Mail<br \/>\nWe\u2019ll now send a test email message. Make sure to replace\u00a0test@example.com\u00a0with your own email address.<\/p>\n<pre class=\"lang:default decode:true\">echo \"Test Email message body\" | mail -s \"Email test subject\" advcha@yahoo.com<\/pre>\n<p>Don\u2019t forget to check your spam folder.<\/p>\n<p>If you still haven\u2019t received any mail, check the mail error log.<\/p>\n<pre class=\"lang:default decode:true\">sudo tail \/var\/log\/mail.log<\/pre>\n<p>NOTE:<br \/>\nTO USE GMAIL SMPT, YOU NEED TO ACTIVATE (SET IT ON) &#8216;Less Secure app&#8217; ON YOUR GMAIL ACCOUNT. LOGIN TO YOUR GMAIL THEN OPEN THIS LINK: https:\/\/www.google.com\/settings\/u\/2\/security\/lesssecureapps<br \/>\nIT&#8217;D REDIRECT YOU THE &#8216;Less Secure app&#8217; SETTING.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>READ: https:\/\/devanswers.co\/configure-postfix-to-use-gmail-smtp-on-ubuntu-16-04-digitalocean-droplet\/ Prerequisites If your Gmail account uses\u00a02-Step Verification, you must\u00a0create an application specific password. If you\u2019re\u00a0not\u00a0using 2-Step Verification, please ensure that your Gmail account is configured to\u00a0allow less secures apps. Remove sendmail sudo apt-get remove sendmail 1. Install Postfix sudo apt-get update sudo apt install -y postfix mailutils Let\u2019s update the package database first. &hellip; <a href=\"https:\/\/myprojects.advchaweb.com\/index.php\/2019\/08\/15\/setup-postfix-on-ubuntu-16-04-localhost-and-use-gmail-smtp\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Setup Postfix on Ubuntu 16.04 Localhost and Use Gmail SMTP&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13,17,78],"tags":[],"class_list":["post-4541","post","type-post","status-publish","format-standard","hentry","category-tutorial","category-ubuntu","category-ubuntu-16-04"],"_links":{"self":[{"href":"https:\/\/myprojects.advchaweb.com\/index.php\/wp-json\/wp\/v2\/posts\/4541","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/myprojects.advchaweb.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/myprojects.advchaweb.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/myprojects.advchaweb.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/myprojects.advchaweb.com\/index.php\/wp-json\/wp\/v2\/comments?post=4541"}],"version-history":[{"count":4,"href":"https:\/\/myprojects.advchaweb.com\/index.php\/wp-json\/wp\/v2\/posts\/4541\/revisions"}],"predecessor-version":[{"id":10554,"href":"https:\/\/myprojects.advchaweb.com\/index.php\/wp-json\/wp\/v2\/posts\/4541\/revisions\/10554"}],"wp:attachment":[{"href":"https:\/\/myprojects.advchaweb.com\/index.php\/wp-json\/wp\/v2\/media?parent=4541"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/myprojects.advchaweb.com\/index.php\/wp-json\/wp\/v2\/categories?post=4541"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/myprojects.advchaweb.com\/index.php\/wp-json\/wp\/v2\/tags?post=4541"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}