In this tutorial, we will teach you how to send email from the Linux command line. This tutorial will walk you through from initially setting up the configuration file for email purposes to eventually viewing the email in the inbox. In Linux, you can send email from the command line.
Step 1 – Install ssmtp client
First of all, let’s open up the terminal application and type:
sudo apt-get install ssmtp and then hit the enter key.
This will install the ssmtp client on your server.
Step 2 – Continue with the installation
Once you are prompted, enter y to continue with the installation.
Step 3 – Configure SSMTP
When the installation has completed, type “gksugedit /etc/ssmtp/ssmtp.conf” and hit the enter key.
This will open up the ssmtp configuration file in a separate window.
Step 4 – Make changes to the config file
When the editor opens up, type in the email details such as the mail id, password, the client smtp port etc.
Once you are done, you can save the configuration file and close the editor window.
Step 5 – Type ssmtp
Now let’s return back to the terminal application and type “ssmtp” along with your email address over there.
Step 6 – Send an email
With that done, now we will have to manually enter the details such as the email address where the email is to be sent, the email address from which you are sending it and the subject of the email.
For this tutorial, we will be sending an email to ourselves.
Once the details have been entered, let’s press the “ctrl+d” key to send the email.
Step 7 – Email was sent successfully
And the email has been sent. Now let’s open up the web browser and open up the gmail inbox to check whether we have received the email or not. Once you are logged in, you will see that the email which was sent from the terminal application is in the inbox. In this manner, you can send an email in Linux from the command line.