Msmtp is a small but powerful and highly customizable smtp client. You can access gmail smtp using msmtp, which is exactly what I’ll teach in this tutorial.
Step by step instructions:
- Install msmtp and ca-certificates for use with SSL:
sudo apt-get install msmtp ca-certificates
- We’ll create and edit the configuration file using Gedit:
sudo gedit /etc/msmtprc
Now copy and paste the following code in the text editor:
defaults tls on tls_starttls on tls_trust_file /etc/ssl/certs/ca-certificates.crt account default host smtp.gmail.com port 587 auth on user [email protected] password mypass from [email protected]m logfile /var/log/msmtp.log
Needless to say, you have to replace [email protected] with your email and mypass with your password
- It should be readable by anyone. However, we’ll still execute the following command to be sure.
sudo chmod 0644 /etc/msmtprc
- Your msmtp configuration is ready. Lets send a test email to yourself to see if everything’s working properly:
echo -e "Subject: Test Mail\r\n\r\nThis is a test mail" |msmtp --debug --from=default -t [email protected]
Again replace [email protected] with your own email address and execute it. You should receive an email.
These are the exact commands to be used with Ubuntu.
You can replicate the steps for another distibution by using equivalent commands (For eg; yum install in place of apt-get install for centos, redhat, fedora.)