Let's configure Gmail or Amazon SES with Magento2 or Magento 1 or any other php application, basically will configure our server in a way so any php application will then use local php mail but email will route with any SMTP provider. Step 1

Shell
apt-get install msmtp -y
Shell
apt-get install libxml-xpath-perl  -y
Shell
nano ~/.msmtprc

Now will edit or add .msmtprc file

Shell
account gmail
tls on
tls_certcheck off
auth on
host smtp.gmail.com
port 587
user [email protected]
from [email protected]
password Yourpasswordhere

Let's change permission and give proper ownership and copy the file to appropriate location

Shell
chmod 600 ~/.msmtprc
cp -p ~/.msmtprc /etc/.msmtp_php
chown www-data:www-data /etc/.msmtp_php

Now will edit php.ini file so we can tell sendmail to use our Gmail SMTP I am using PHP 7 so my location is different then your's probably, if you are using Ubuntu or any flavor you can simply use

Shell
locate php.ini

 

Shell
nano /etc/php/7.0/fpm/php.ini
nano /etc/php/7.0/cli/php.ini

Now will edit sendmail in php.ini

Shell
sendmail_path = "/usr/bin/msmtp -C /etc/.msmtp_php --logfile /var/log/msmtp.log -a gmail -t"

Lastly will make sure to have our log file

Shell
touch /var/log/msmtp.log
chown www-data:www-data /var/log/msmtp.log

Now goto your Magento2 admin or Magento admin or any PHP Application to try to sendmail email it will use Gmail or Amazon SES to send emails out, you just need to modify your msmtp file

Was this worth your time?