Sendmail vs Postfix – both are Mail Transfer Agents (MTA) used for sending mail from a Linux host. The primary concerns when deciding which MTA to use come down to performance, ease of use, and security.
Postfix is the most commonly used MTA, for good reason. It is a security oriented mail server with good documentation and performance.
Sendmail is comparable with the primary difference being sendmail is not as security focused and generally less performant.
With either agent you can view the same log for success and failure logs at
Ultimately, we recommend using postfix over sendmail. Assuming both are installed, to switch you should first make sure there are no undelivered messages in your queue, and the simply run the following commands to shutdown sendmail and startup postfix.
service sendmail stop service postfix start
In the following examples we will demonstrate how to configure sendmail vs postfix with a relay host as well as how to perform various actions within each service.
If you notice messages are not being delivered from your host or messages are not being delivered in a timely manner you should check the queue. To view the sendmail queue, run the following command:
If you suspect the cause for delay or failed mail attempts has been fixed, you can resend the mail queue by running the following command, where -v outputs verbose logging of the resend attempts.
sendmail -q -v
Occasionally a queued item will be locked and a resend attempt will not work. To remove the lock on a queued item, first check the sendmail process by running:
ps awx | grep sendmail
In the output you should see an item in the queue with a process id that needs to be removed. To remove the lock, simply kill the process with:
kill -9 <process_id>
To troubleshoot your sendmail installation and configuration it may be helpful to send a test email directly from the command line with sendmail. You can do this by echoing the subject and piping that into the sendmail command, after ensuring that the sendmail service is running.
echo "Subject: sendmail test" | sendmail -v firstname.lastname@example.org
You may also be more detailed in your test email with a sample mail text file. Create a file named mail.txt with the following data:
To: email@example.com Subject: sendmail test From: firstname.lastname@example.org
To send the test email with data from mail.txt, run:
sendmail -vt < mail.txt
How to configure a sendmail relay host
To send email from your linux host to an outside domain, you must have an smtp server configured in your domain. For this example we will assume the smtp host is smtp.example.com. Follow these steps to set up a sendmail relay host.
/etc/mail/sendmail.mc file (not the
/etc/mail/sendmail.cf file, as it will be overwritten with any changes), find the line containing the following:
Remove the dnl from the beginning of that line.
Change smtp.your.provider to your actual smtp relay host, for example smtp.example.com
Save the file and run the following command:
If you receive the following message
"WARNING: 'sendmail.mc' is modified. Please install package sendmail-cf to update your configuration."
then install that package in accordance with your OS and package manager.
For Redhat, that command is:
dnf install sendmail-cf
Rerun the make command.
Restart the sendmail service as root with:
service sendmail restart
For the same reasons as with sendmail, to check the postfix queue, run the following command. It will show the list of queued email, deferred email, and pending email.
To troubleshoot your postfix installation and configuration it may be helpful to send a test email directly from the command line with postfix. You can do this by echoing the message and piping that into the mail command. To send a test email with postfix, run the following command, first making sure that the postfix service is running.
echo "Test Postfix" | mail -s "Test Postfix" email@example.com
To display the email header and content of a specific message:
postcat -q <QUID>
To find how many emails are stuck in the postfix queue, first list the email in the queue and pipe the output into grep for a count search.
postqueue -p | grep -c "^[A-Z0-9]"
To retry delivery of all email in the postfix queue:
To delete all email in the postfix queue or to delete a specific email in the queue
postqueue -d ALL postqueue -d <QID>
To retry one specific email instead of the entire postfix queue, run:
postqueue -i <QID>
How to configure a postfix relay host
To send email from your linux host to an outside domain, you must have an smtp server configured in your domain. For this example we will assume the smtp host is smtp.example.com. Follow these steps to set up a postfix relay host.
/etc/postfix/main.cf file, find the
relayhost parameter and set it as your smtp server, in this example it would be smtp.example.com.
This article has demonstrated sendmail vs postfix commands, as well as provided arguments as for which MTA will best suit your needs. While we recommend postfix over sendmail, you can remove either package from your OS as they should not both be installed or running at the same time.
To remove sendmail from a Redhat server with dnf, run the following command:
dnf remove sendmail
To remove postfix from a Redhat server with dnf, run the following command:
dnf remove postfix
Please leave a comment if you have any questions or would like to see more examples with postfix or sendmail.