Good day my dear Linux Yogi’s,
this article illustrates how to setup and configure ssmtp the send-only smtp server by utilizing a gmail account. It should be fairly easy to adapt this to any other public email service. In order for that to work you have to loosen up your gmail security. Log in to your Gmail account. Click on your Account Picture in the top right hand corner and then select “My Account”. Under “Sign-in & Security” click on “Signing in to Google” then scroll down until you see the option “Allow less secure apps” and switch it on. That is it for the Gmail part.
In the next step we have to update out system and install ssmtp. Run the following commands to accomplish it.
sudo apt-get update sudo apt-get upgrade sudo apt-get dist-upgrade sudo apt-get install ssmtp
Now that ssmtp is installed lets go ahead and configure it. There are essentially two files we have to worry about to get ssmtp running with your Gmail account. The first file we are going to work on is: /etc/ssmtp/ssmtp.conf
# # Config file for sSMTP sendmail # # The person who gets all mail for userids < 1000 # Make this empty to disable rewriting. root=postmaster # The place where the mail goes. The actual machine name is required no # MX records are consulted. Commonly mailhosts are named mail.domain.com mailhub=mail # Where will the mail seem to come from? #rewriteDomain= # The full hostname hostname=ubuntu-server # Are users allowed to set their own From: address? # YES - Allow the user to specify their own From: address # NO - Use the system generated From: address #FromLineOverride=YES
Lets make the following changes (in Bold):
# # Config file for sSMTP sendmail # # The person who gets all mail for userids < 1000 # Make this empty to disable rewriting. firstname.lastname@example.org # The place where the mail goes. The actual machine name is required no # MX records are consulted. Commonly mailhosts are named mail.domain.com mailhub=smtp.gmail.com:587 AuthUseremail@example.com AuthPass=Your-Gmail-Password UseTLS=YES UseSTARTTLS=YES # Where will the mail seem to come from? rewriteDomain=gmail.com # The full hostname firstname.lastname@example.org # Are users allowed to set their own From: address? # YES - Allow the user to specify their own From: address # NO - Use the system generated From: address FromLineOverride=YES
The second file we have to edit is /etc/ssmtp/revaliases
# sSMTP aliases # # Format: local_account:outgoing_address:mailhub # # Example: root:email@example.com:mailhub.your.domain[:port] # where [:port] is an optional port number that defaults to 25.
and add the following line:
Now the configuration is one. Lets give it a try to see if it is actually working. Enter the following command:
SSMTP is now awaiting some input from you. Enter the following:
To: firstname.lastname@example.org From: email@example.com Subject: ssmtp test email This is a Test email
Make sure you have a line between the Subject and the email message. When you are done writing your email use <CTRL> + <D> to finish the email so it can be send.
! ssmtp also created a symbolic link from /usr/sbin/ssmtp to /usr/sbin/sendmail so that local service that use sendmail for sending out alert or such can continue doing it that way. So there is not need to adjust every service installed on your system.
So I hope that this illustration was useful and that you liked it. Please consider subscribing to my blog and registering to the blogs forum. Also if you need me to write something up for you please use the contact form and drop me a line.
Thank you very much for reading and until next time, Namaste my friends!