How Do You Set up a Send-Only (Postfix) Email Server on a Linux RHEL AWS Instance?

Problem scenario
You have a monitoring tool on a RedHat Enterprise Linux server that needs to send out emails upon certain events happening. You want to install and configure an email server. You need to send outbound emails, but you do not need to receive inbound emails. How do you configure RHEL to be able to send out regular emails over the internet?

Prerequisite
This assumes that Postfix has been installed. For Debian/Ubuntu Linux, postfix is often installed by default. If it is not, run this command:
sudo apt -y install postfix # accept the various options by mostly accepting the defaults and using your best judgement

Solution
1. Ensure that the AWS Security Group allows for outbound connectivity over port 25.
2. Log into the RHEL server.
3. Run this command: hostname -f
4. Find the internal IP address. It is usually in the FQDN of an AWS server. You could run this command (and ignore the /20 at the end of its output):

ip addr show | grep eth0 | grep inet | awk '{print $2}'

You'll need this later.

5. Edit the /etc/postfix/main.cf file (e.g., with sudo vi /etc/postfix/main.cf). It should have lines like these at the very end (but replace contint.com with FQDN of the server and replace 10.10.10.10 with the internal IP address as found in steps 3 and 4 above).

inet_interfaces = localhost, 10.10.10.10
inet_protocols = all
mydestination = $myhostname, localhost.$mydomain, $mydomain
myhostname = contint.com

6. Now that the last lines of the main.cf file have been updated and the file is saved, restart the postfix server. Run this command:

sudo service postfix restart

7. If you have a DNS server so the FQDN resolves, skip this step. Otherwise update the /etc/hosts file to have an entry like this (where FQDN is the one found in step 3 and where 10.10.10.10 is the internal IP address as found in step 4):

10.10.10.10 FQDN

8. Optional step. Test it. Type in the following but replace contint.com below with your mail server's FQDN and press enter after each line:

sudo yum -y install telnet
telnet contint.com 25
helo contint.com
mail from: webmaster@contint.com
rcpt to: goodperson@gyahoomail.com
DATA
This is just a test.
.
quit

Another Possible Solution
Another way to do this is with Python; to learn how to use Python and not install anything else, see this external posting.

Leave a comment

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