How to send mail with sendmail command line

The classic sendmail command!

To send an email using the sendmail command line, you'll need to follow these steps:

Step 1: Prepare your email

Create a text file containing the email message you want to send. The file should have the following format:

To: [email protected]
From: [email protected]
Subject: Your email subject

Your email body

Replace [email protected], [email protected], and Your email subject with the actual values.

Step 2: Use the sendmail command

Open a terminal or command prompt and navigate to the directory where your email file is located. Then, use the following command:

sendmail [email protected] < your_email.txt

Replace [email protected] with the email address of the recipient, and your_email.txt with the name of your email file.

Options and flags

You can customize the sendmail command by adding options and flags. Here are some common ones:

For example:

sendmail -t -f [email protected] -s "Your email subject" [email protected] < your_email.txt

Tips and variations