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

 In All Tutorials
Last Updated On November 04, 2019

Linux by default comes with a mail command which can be used to sendmail from command line. Here in this tutorial let's understand all the pre-requisites for how to test sendmail from Linux Command Line and everything else that you need to know before testing a sendmail.

Prerequisites:

You need to just ensure that there is a Mail Transfer Agent (MTA) installed e.g. sendmail or postfix and configured on your server.

By default, mail command won't be able to send mails. It can just accept your mail sending request and the request then can be forwarded to the MTA to sendmail.

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:

Postfix is definitely the most powerful open source to send mail, but if you just want to send a simple test mail, then try ssmtp or msmtp.
SSMTP is actually depreciated and hence it is recommended to use its alternative like msmtp or OpenSMTPD.

These are lighter version MTAs and doesn't necessarily require you to keep running their daemon programs like it is there in case of postfix. It has most of the feature support like secure mail sending or sending mail with Gmail.

Quick Sendmail Test from the Linux command line

Once the installation is done, just run the following command and you will be able to send a test mail from your command line:

echo "My message" | mail -s subject user@gmail.com

Using echo with pipe avoids the unnecessary prompts or confirmation from getting displayed.

 

Optional Read

If you have installed postfix or Sendmail, then you can directly do sendmail test using the below command:

/usr/sbin/sendmail user@domain.com < /filecontent/to/send

For Ubuntu users: You need to first install mailutils and then set up a mail sending server or MTA.

Use the below command to install mailutils:

sudo apt-get install mailutils

For CentOS users: You need to first install mailx and then set up a mail sending server or MTA.

sudo yum install -y mailx

Note: If you have set up a mail sending server or Mail Transfer Agents like Postfix or sendmail and trying to send test mail using Gmail SMTP and getting some authentication error then no need to worry because there are few additional security-related configurations which you need to be done on Gmail.

To sendmail from Gmail, you need to turn on the "Access for Less Secure Apps". For more help, refer to this link.

Recent Posts

Leave a Comment

We are always looking for fresh talent to contribute to our blog. If you have a knack for writing and a passion for email marketing, we would love to have your post on our Guest Blog .

Submit a Guest Post
Pepi thinking

Start typing and press Enter to search

Thank you for your details!

Fill out your information below, and we will send you a PepiAlert, that will describe your domain’s email deliverability situation. Please note that your email address must match the domain, or the domain must be owned by the company matching the email address. We have the right to refuse the request, if we can’t verify the information.

*All fields are required