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.
In this recipe, we'll combine several options:
mydomain.lan
domainmailhost.mydomain.lan
mailserverTo complete this recipe, perform the following steps:
/etc/postfix/main.cf
with your favorite editor.inet_interface
to accept mails on any interface through the following command:inet_interface = all
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.
relayhost
directive to point to mailhost.mydomain.lan
, as follows:relayhost = mailhost.mydomain.lan
postfix
file./etc/postfix/sender_access
with the following contents:mydomain.lan OK
/etc/postfix/access
file using the following command:~]# postmap /etc/postfix/access
postfix
, as follows:~]# systemctl restart postfix
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
.
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.