SMTP (Simple Mail Transfer Protocol) is a protocol for sending email messages between servers. Most email systems that send mail over the Internet use SMTP to send messages from one server to another, and to deliver messages to local mail clients like Microsoft Outlook or Apple Mail.
SSMTP is a simple and lightweight utility that allows users to send emails from the command line or shell scripts. It is especially useful for systems that don’t have a full-blown mail server installed, such as a headless server or a machine running on a cloud platform.
In this article, we will show you how to set up and configure SSMTP on your Linux machine.
Step 1: Install SSMTP
The first thing you need to do is install SSMTP on your Linux machine. Depending on your distribution, you can use the package manager to install it.
- For example, On a Debian or Ubuntu machine, you can use the following command:
sudo apt update && apt install ssmtp
- On a CentOS or Fedora machine, you can use the following command:
sudo yum install ssmtp
Step 2: Configure SSMTP
Once SSMTP is installed, you need to configure it by editing the configuration file located at “/etc/ssmtp/ssmtp.conf”. For this tutorial, I am using the Gmail SMTP server. You can use any of the remote SMTP servers that allowed you to send emails from your system.
Open the file in a text editor, such as nano or vi:
sudo nano /etc/ssmtp/ssmtp.conf
Change/Update the following lines in the configuration file:
The above details are as followings,
- mailhub: your smtp server host/ip with port.
- UseSTARTTLS: Set it to Yes if the SMTP server uses TLS or else No.
- AuthUser: Use Gmail ID here
- AuthPass: Use Gmail ID’s password
- TLS_CA_File: This may be required sometimes If you face an issue like “send-mail: Cannot open smtp.gmail.com:587”
Step 3: Send a Test Email
Now test the setup by sending a test email to an email address. First compose the mail in a text file like:
Add email content, for example:
msg.txtFrom: [email protected] Subject: This is the Subject Line Email content line 1 Email content line 2
Then send an email to “[email protected]” using the
ssmtp [email protected] < msg.txt
Check your mailbox for the new email.
Step 4: Set the Default Mail Transfer Agent
Now set SSMTP as your default mail server, So that you can simply use the mail command to send emails through SSMTP.
alternatives --config mtaThere are 2 programs that provide 'MTA'. Selection Command ----------------------------------------------- 1 /usr/sbin/sendmail.ssmtp *+ 2 /usr/sbin/sendmail.sendmail Enter to keep the current selection[+], or type selection number: 1
In case of no other mail client is configured, You should see a message like "no alternatives for mta". In that case, SSMTP is the default mail client.
To verify the changes, execute:
sendmail -VsSMTP 2.64 (Not sendmail at all)
In this article, we showed you how to set up and configure SSMTP on your Linux machine in 5 simple steps. First, we installed SSMTP using the package manager. Then, we configured SSMTP by editing the configuration file and setting the default mail transfer agent. After that, we tested SSMTP by sending an email from the command line. Finally, we showed you how to use SSMTP in shell scripts to send automated emails.
SSMTP is a simple and lightweight utility that allows you to send emails from the command line or shell scripts. It is especially useful for systems that don't have a full-blown mail server installed, such as a headless server or a machine running on a cloud platform. With a few simple configurations, you can easily use SSMTP to send emails from your Linux machine.