How to Send Mail From Command Line Using SMTP Server in Linux.

SSMTP is a program which allow to send email to a designed mailhost (mailhub). It accepts a mail stream on standard input with recipients on the command line.We can send mail using SSMTP program & failed messages are placed in dead.letter in the sender’s home directory.

SSMTP delivers emails from a user’ system or a server to a configured mail host. SSMTP is not an mail server and does not receive emails or manage a queue.


  • SMTP Configurations (SMTP server details and authentication credentials)
  • Configure Gmail SMTP/ready with any other custom SMTP server details.

Google SMTP server configurations:

  • SMTP Server/Hostname:
  • SMTP Username:[email protected]
  • SMTP password: password
  • SMTP Port: 587
  • TLS/SSL: Required

Update the System.

apt-get update

Install SSMTP

apt-get install ssmtp -y

Configure sSMTP.

vim /etc/ssmtp/ssmtp.conf

Add the following line in the ssmtp.conf file.

[email protected]

Add reverse aliases

vim /etc/ssmtp/revaliases

Add the line:

root:[email protected]

Create a message to send.

vim msg.txt

Add the following message.

To: [email protected]
From: [email protected]
Subject: Example email


Send mail.

/usr/sbin/ssmtp [email protected] < msg.txt

Sendmail in a single line.

echo "Test message using ssmtp" | sudo ssmtp -vvv [email protected]

ssmtp to send mail from a shell script.Create a shell script file.


Add the following line.

SUBJECT="Test Subject"
TO="[email protected]"
MESSAGE="This is a test mail"

echo $MESSAGE | sudo ssmtp -vvv $TO

Set the permission.

chmod 755 

Run the script.

sudo ./



2 responses to “How to Send Mail From Command Line Using SMTP Server in Linux.”

    • Hi,

      Thanks for your update.

      This is basic blog and you are most welcome if you have something to add.

      Just register yourself and add the same, we would love to read it.

Leave a Reply