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

Problem scenario
You have a monitoring tool on a 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 Linux SUSE to be able to send out regular emails over the internet?

Solution
1. Ensure that the security group allows for outbound connectivity over port 25.
2. Log into the Linux SUSE server.
3. Run this command: hostname

4. Ensure that the hostname does not have numeric sequences like an IP address. For example, the hostname should not have something like this (note the hyphens): ip-172-31-1-1

It seems unusual, but it bears repeating: you may encounter problems if the alphanumeric hostname has numeric sequences -- such are a tell-tale sign of an IP address. We have had problems with sequences of numbers in the hostname. To change the hostname, you would modify /etc/hostname so it has the hostname you want. Make sure that the /etc/hosts file has a stanza with the internal IP address of the server and the hostname in /etc/hostname. Once these are changed you should reboot the server.

5. 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 the result of the above command later.

6. Run this command to install Postfix: sudo zypper -n install postfix

7. Edit the /etc/postfix/main.cf file.

7.a. The /etc/postfix/main.cf should have lines like these at the very end (but replace contint.com with the FQDN of the server 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
myhostname = contint.com

7.b. In the /etc/postfix/main.cf, comment out the previous stanzas for inet_interfaces and myhostname in the file. Use the "#" (with no quotes) to do this. Save the changes.

8. 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 contint is the hostname in step 3 and where 10.10.10.10 is the internal IP address as found in step 4):

10.10.10.10 contint

9. Restart the postfix server. Run this command: sudo service postfix restart

10. Optional step. Test it. Type in the following but do these four things first to draft the commands specific to your environment: one, replace contint in the helo command with the plain hostname (the one that results from the "hostname" command); two, replace webmaster@contint.com with the sender's email address, or the one you want to appear as the sender; three, replace "goodperson@gyahoomail.com" with the destination email address, and four press enter after each line:

telnet 127.0.0.1 25
helo contint
mail from: webmaster@contint.com
rcpt to: goodperson@gyahoomail.com
DATA
This is just a test.
.
quit

An Alternative Way To Send Email
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 *