Red Hat Training

A Red Hat training course is available for RHEL 8

Chapter 11. Mail Transport Agent

Mail Transport Agent (MTA) transports email messages between hosts using SMTP. The delivery of email messages can include several MTAs while reaching their destination. During the process of message delivery, the usage of MTA depends on the MTAs or the access configuration of the network.

Sendmail and Postfix are the two MTAs offered by RHEL.

11.1. Sendmail

Sendmail is available through the AppStream repository. Sendmail is not a Message User Agent (MUA). You cannot browse and manage your incoming mail through a user interface, but it can work as an SMTP client. The sendmail.mc package helps to reconfigure the Sendmail.

11.2. Installing Sendmail

To install Sendmail, perform the following steps:

Procedure

  1. Update all the installed packages with the latest version, so that all the dependent packages are updated

    # yum update
  2. Install Sendmail

    # yum install sendmail
  3. Use sendmail command to send email via command line

    For Example:
    
    # echo "This is a test email" | sendmail -s "Test Email"
    example@receipientemail.com

Verification

  • Verify sendmail is installed

    $ rpm -qa | grep sendmail

11.3. Postfix

A Postfix transfer agent handles all processes related to mail delivery. Postfix is available through the BaseOS repository. However, postfix-mysql or postfix-ldap subpackages are built from the postfix source RPM that is available through the Appstream repository.

Postfix configuration files are stored in the /etc/postfix/ directory.

Following is a list of the commonly used files:

  • access:— it is used for access control and specifies hosts that are allowed to connect to Postfix.
  • main.cf:— it is the global Postfix configuration file, and specifies many configuration options.
  • master.cf:— it specifies Postfix interaction with various processes to accomplish mail delivery.
  • transport:— it maps email addresses to relay hosts. The aliases file is a configurable list required by the mail protocol that describes user ID aliases. It is in the /etc directory and is shared between Postfix and Sendmail.

11.4. Installing Postfix

If the mail server package is not selected during the system installation, Postfix will not be available by default. Perform the following steps to install Postfix:

Prerequisites

Procedure

  1. To install postfix

    # yum install postfix
  2. To start and enable the postfix service

    # systemctl start postfix
    
    # systemctl enable postfix

Verification

  • Verify if the postfix service is running

    $ rpm -qa | grep postfix
  • Restart the postfix service, in the following scenarios:

    • if the output is stopped/waiting or not running
    • after changing any options in the configuration files under the /etc/postfix/ directory in order for those changes to take effect

      # service postfix restart

Additional resources

  • /etc/postfix/main.cf configuration file.

11.5. Configuring Postfix

The main.cf is the global Postfix configuration file and specifies many configuration options.

Procedure

Following are few options you can add in the /etc/postfix/main.cf file to configure Postfix:

  1. myhostname:- replace host.domain.tld with the mail server’s hostname.

    For example:
    
    myhostname = mail.example.com
  2. mydomain:- replace domain.tld with the domain mail server.

    For example:
    
    mydomain = example.com
    Note

    With correct DNS setups, the myhostname and mydomain options should be autodetected and set automatically without user intervention.

  3. mail_spool_directory:- allows specifying the location of the mailbox files.

    For example:
    
    mail_spool_directory = /var/mail
  4. mynetworks:- add the list of valid and trusted remote SMTP servers. This option should include only local network IP addresses or networks separated by commas or whitespaces. Adding local network addresses avoids unauthorized access to mail servers.
  5. Uncomment the inet_interfaces = all line. This option allows Postfix to be accessible from the internet. With its default configuration, it will only receive emails from the local machine.
  6. Comment the inet_interfaces = localhost line. This option allows Postfix to be accessible from the internet. With its default configuration, it will only receive emails from the local machine.
  7. Restart the postfix service.

    # systemctl reload postfix

Verification

  • To verify an email communication between local users on the system

    # echo "This is a test message" | mail -s <SUBJECT> <name@mydomain.com>

    Press Ctrl+D to send the message.

  • To verify the open relay is not active on your new mail server, send an email from your mail server to a domain that your new mail server doesn’t accept mail:

    hello mydomain.com
    mail from: name@mydomain.com
    rcpt to: name@notmydomain.com
    
    554 Relay access denied - the server is not going to relay.
    
    250 OK or similar-  the server is going to relay.
    
    The 'rcpt to' option should only accept mail addressed to addresses @mydomain.com
Important

In case of errors, check the `/var/log/maillog file.

Additional resources

  • /etc/postfix/main.cf configuration file.