Guide to send an email from CLI using SMTP in Linux

Category : Linux/ Unix

Electronic mail is a method of exchanging messages between people using electronic devices. There are several methods to send an email, in this guide we are going to focus on sending an email from Linux CLI using SMTP.

Requirements send an email from CLI using SMTP :

  • Linux with sudo permissions
  • SMTP details for your email

Procedure :

  1. Installing epel-release on your system by using the following command.
    yum install epel-release
  2. Installing SMTP on your system by using the following command.
    sudo yum install ssmtp
  3. Open the following file in an editor.
    sudo vi /etc/ssmtp/ssmtp.conf
  4. Add the following lines to the file:
    TLS_CA_FILE=/etc/pki/tls/certs/ca-bundle.crt
    mailhub=smtp.gmail.com:587
    useSTARTTLS=YES
    [email protected]
    AuthPass=your_password
    How to send email from Linux using SMTP
    Save the file by pressing the Esc key, type `:wq` to write the file and exit the editor.
    Note : mailhub could be already defined in the ssmtp.conf file and make sure you edit the definition instead of adding a new mailhub definition.
  5. Send the email using the following command.
    echo -e "To: [email protected]\nFrom: Sender Name <[email protected]>\nSubject: Email from CLI\n\nTest Email sent using SMTP from CLI" | ssmtp -v [email protected]

Congratulations now you know how to send email from Linux using SMTP.

Read more helpful guides like this on our blog. Click here

List and edit cronjobs guide for Linux OS