Configuring smtp

Many programs use (or can be configured to use) SMTP to send messages about their status and so on. By default, postfix is configured to deliver all messages locally and not respond to incoming mails. If you have an environment of multiple servers, this can become quite tedious to log on to each server to check for new mail. This recipe will show you how to relay messages to a central mail relay or message store that also uses SMTP.

Postfix is installed by default on RHEL 7.

How to do it…

In this recipe, we'll combine several options:

  • We'll allow the server to accept incoming mails
  • We'll only allow the server to relay messages from recipients in the mydomain.lan domain
  • We'll forward all mails to the mailhost.mydomain.lan mailserver

To complete this recipe, perform the following steps:

  1. Edit /etc/postfix/main.cf with your favorite editor.
  2. Modify inet_interface to accept mails on any interface through the following command:
    inet_interface = all
  3. Add the smtpd_recipient_restrictions directive to only allow incoming mails from the mydomain.lan domain, as follows:
    smtpd_recipient_restrictions =
        check_sender_access hash:/etc/postfix/sender_access,
        reject

    As you can see, the last two lines are indented. The postfix considers this block as one line instead of three separate lines.

  4. Add the relayhost directive to point to mailhost.mydomain.lan, as follows:
    relayhost = mailhost.mydomain.lan
  5. Now, save the postfix file.
  6. Create /etc/postfix/sender_access with the following contents:
    mydomain.lan OK
  7. Next, hash the /etc/postfix/access file using the following command:
    ~]# postmap /etc/postfix/access
    
  8. Finally, restart postfix, as follows:
    ~]# systemctl restart postfix
    

There's more…

To monitor your mail queue on the system, execute the following:

~]# postqueue -p

Whenever your mail relay cannot forward mails, it stores them locally and tries to resend them at a later time. When you restore the mailflow, you can flush the queue and attempt delivery by executing the following:

~]# postqueue -f

The kind of setup presented in this recipe is quite simple and assumes that you don't have malicious users on your network. There are software that allow you to mitigate spam and viruses. Popular solutions for this are spamassassin and amavis.

See also

For more information on using postfix with RHEL 7, go to https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/System_Administrators_Guide/s1-email-mta.html#s2-email-mta-postfix.

For more information on postfix, check out the postfix rpm (rpm -ql postfix) or go to http://www.postfix.org/. This site provides good documentation and how to's for a large number of scenarios.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset