How to send an email with SendMail ?

About

This article shows you how to send an email with sendmail.

Note
  • 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; 
	boundary="----=_Part_0_1435861572.1661430753875"

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

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

The attachement
------=_Part_0_1435861572.1661430753875--





Discover More
What is Sendmail ?

Sendmail is: * a mail transfer agent (MTA) for linux (ie a SMTP server, running on the port 25). * a command line (MUA) to send a message Almost all MTAs provide a sendmail interface making it...



Share this page:
Follow us:
Task Runner