Basic SSMTP setup for sending email from bash scripts etc.

This article is aimed at those who only require a basic/simple email sending setup for use in shell scripts etc.

Packages to be installed

Packages to be installed if not already.

sudo apt install ssmtp

Configure SSMTP

Configure machine you will be sending emails from by editing /etc/ssmtp/ssmtp.conf.

sudo nano /etc/ssmtp/ssmtp.conf

# The full hostname
hostname=ks-kenobi

# 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

# Kathenas
UseTLS=YES
root=SENDING_EMAIL_ADDRESS
mailhub=SENDING_EMAIL_ACCOUNT_SERVER_ADDRESS
AuthUser=SENDING_EMAIL_ACCOUNT_USERNAME
AuthPass=SENDING_EMAIL_ACCOUNT_PASSWORD

Bash script for testing

#!/bin/bash

sender="SENDING_EMAIL_ADDRESS"
recipient="RECIPIENT_EMAIL_ADDRESS"
subject="Test Email"
body="This is a test email sent using SSMTP."

echo -e "Subject:${subject}\n${body}" | /sbin/ssmtp -f "${sender}" "${recipient}"