SSMTP is a tool that delivers emails from a computer or a server to a configured mail host.
SSMTP is not an email server itself and does not receive emails or manage a queue.
One of its primary uses is for forwarding automated email (like system alerts) off your machine and to an external email address.
You would need the following things in order to be able to complete this tutorial successfully:
In order to install SSMTP you’ll need to first update your apt cache with:
Then run the following command to install SSMTP:
Another thing that you would need to install is
mailutils, to do that run the following command:
- sudo apt install mailutils
Now that you have
ssmtp installed, in order to configure it to use your SMTP server when sending emails you need to edit the SSMTP configuration file.
Using your favourite text editor opent the
- sudo nano /etc/ssmtp/ssmtp.conf
You need to incldue the your SMTP configuration:
Save the file and exit.
Sending emails with SSMTP
Once your configuration is done, in order to send an email just run the following command:
- echo "Here add your email body" | mail -s "Here specify your email subject" firstname.lastname@example.org
You can run this directly in your terminal or include it in your bash scripts.
Sending A File with SSMTP (optional)
If you need to send files as attachments, you can use
mpack run the following command:
Next, in order to send an email with a file attached, run the following command
- mpack -s "Your Subject here" your_file.zip email@example.com
The above command would send an email to
firstname.lastname@example.org with the
SSMTP is a great and reliable way to implement SMTP email functionality directly in bash scripts.
For more information about SSMTP I would recommend checking the official documentation here.
Hope that this helps!