How to Test Sendmail from Linux Command Line? [SOLVED]

Published on 2019-10-17· Updated on 2024-01-25

The author voluntarily contributed this tutorial as a part of Pepipost Write to Contribute program.


Linux has a default command for sending mail from the command line. This tutorial covers prerequisites and important information to get started.


You need to install and configure a Mail Transfer Agent (MTA) such as Sendmail or Postfix on your server. The MTA is responsible for transmitting email messages between different hosts or systems. It is a critical component of the email delivery process. 

When you send an email, the MTA routes the message from the sender's system to the recipient's system. The mail command can only accept your mail-sending request and forward it to the MTA to send the mail.

Optional Step: In case you don't have Sendmail or Postfix installed

You can follow the below links to install and configure a Mail Transfer Agent:

It is recommended to use lighter MTAs like msmtp or OpenSMTPD instead of Postfix. They support secure mail sending with Gmail.

Quick Sendmail Test from the Linux command line

After completing the installation, use the below command to send a test email from your command line:

echo "My message" | mail -s subject [email protected]

Using echo with pipe avoids unnecessary prompts or confirmation from getting displayed, and -s denotes the mail’s subject.

Optional Read

If you have installed Postfix or Sendmail, you can test Sendmail using the command below:

/usr/sbin/sendmail [email protected] < /filecontent/to/send

Ubuntu users need to install mailutils and set up a mail-sending server or MTA. Use the command below to install mailutils:

sudo apt-get install mailutils

For those using CentOS, installing mailx before configuring a mail-sending server or MTA is necessary.

sudo yum install -y mailx

Due to authentication errors, you might face trouble while sending test mail using Gmail SMTP with a mail-sending server or Mail Transfer Agents like Postfix or Sendmail. In such a case, you will need to complete additional security-related configurations on Gmail. Enable ‘Access for Less Secure Apps’ to send mail from Gmail. For more assistance, refer to this link. 

We are a community of email enthusiasts. If you have further queries, feel free to drop an email to [email protected] , and we would be happy to help you.

Excited about the latest in Bulk Email Marketing! Check out this insightful blog on Gmail and Yahoo updates in the email marketing landscape.
Explore the Blog - Here
Stay ahead of the game with valuable insights on optimizing your email campaigns! 📬

Grade My Email
Check your spam now?

Netcorecloud's toolkit is the solution to all your email problems.

Dibya Sahoo🥑

Co-founder, Pepipost

Over 12 years of experience, building products to deliver emails ~ 🥑 Developer Relations Guy ~ 🎙️ Speaker

You can also explore

Netcore connects & unifies your data across all sources, connects to your marketing channels and provides you with control over AI Powered automation and personalization.

Deploy emails that are
screenshot worthy!

Stop settling for static emails - use Netcore's platform to create dynamic, interactive emails that convert.
Let's Deploy
Get Started Now