How to send an email with the SendMail command line client ?


This article shows you how to send an email with the sendmail command line client.


You should have a smtp server installed.

  • The sendmail command may be the original or the one provided with your SMTP server. This documentation was tested with the sendmail of the postfix MTA.


You can set options at the command line, for instance -F (Set the sender full name) - They correspond to the smtp commands.

How to send a basic text email

Type a mail file for the smtp data (headers are separated from the body by a blank line)

Subject: Hello World !
From: nico
To: [email protected]

This is my first mail 

Excited I am

  • You can pipe it in to sendmail
sendmail [email protected] < mail.eml
cat mail.eml | sendmail [email protected]
  • or with a echo
echo -e "Subject:Hello World \n\n This is my first mail \n" | sendmail [email protected]
  • or enter the below command, type in your message, then press Enter and type in a dot and press Enter again.
sendmail [email protected]

How to send an email with file attachments

Sendmail does not have any option to set mail attachments.

Therefore, you should create a mime message with attachement before piping it to sendmail.

Example of message with a text file attachement

Date: Thu, 25 Aug 2022 14:32:33 +0200 (CEST)
From: [email protected]
To: [email protected]
Message-ID: <912285664.1.1661430753895@localhost>
Subject: An multi-part mail example
MIME-Version: 1.0
Content-Type: multipart/alternative; 

Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit

 This is the email with a text file attachment.
Content-Type: text/plain; charset=us-ascii; 
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename=BMail16334979482245192500.txt

The attachement

Discover More
What is Sendmail ?

Sendmail was the first well-known SMTP server. The server has the following components: * a mail transfer agent (MTA) to send mail to the outside world * a mail deliver agent (MDA) to receive email...

Share this page:
Follow us:
Task Runner