• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer

Mister PKI

SSL Certificates * SSL Tools * Certificate Decoder

  • Buy SSL Certificates
  • Blog
  • OpenSSL
  • Keytool
  • SSL Tools
  • Donate

Sendmail vs Postfix – Mail Transfer Agent Comparison

August 16, 2022 by Mister PKI Leave a Comment

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 /var/log/maillog

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.

Sendmail Examples

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:

sendmail -bp

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 info@misterpki.com

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: info@misterpki.com
Subject: sendmail test
From: test@your.domain

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.

In the /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:

define(`SMART_HOST', `smtp.your.provider')

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:

/etc/mail/make

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

Postfix Examples

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.

postqueue -p

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" info@misterpki.com

You can enhance the mail command with postfix to define a sender as well by adding the -r info@example.com option.

echo "Test Postfix" | mail -r info@example.com -s "Test Postfix" info@misterpki.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:

postqueue -f

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.

In the /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.

How to change the send as domain in postfix

Postfix sends mail by default as the user sending mail at the host name. So if your user is apache and your host is test.example.com, mail will send by default as apache@test.example.com. There are a few different configuration options with the /etc/postfix/main.cf file, and we will demonstrate one of those.

In the /etc/postfix/main.cf file, find the myorigin property and set it to equal the domain you are sending from. This is useful if mail is failing due to dkim or spf records when sending from a subdomain.

Conclusion

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.

Read more of our posts.

linux

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Popular Posts

PKCS12

openssl s_client

Keytool

Keytool list

ECDSA vs RSA

OpenSSL

PKCS7

Certificate Decoder

Training Courses

Top online courses in IT & Software

Cyber Security Training

Udemy - The Complete Internet Security Privacy Course icon

Buy SSL Certificates

The SSL Store

Comodo Store

Sectigo Store

RapidSSL

Recent Posts

  • pfx password
  • pkcs12
  • Sendmail vs Postfix – Mail Transfer Agent Comparison
  • Python mock datetime now
  • Python get SSL Certificate

Footer

  • Twitter
  • YouTube

Pages

  • About Mister PKI
  • Blog
  • Compare and Buy Affordable PKI Certificates
  • Contact Us
  • Full Disclosure
  • Privacy Policy
  • SSL Tools – Certificate Decoder and Certificate Checker

Copyright © 2022