It's a quick guide to install a postfix server on CentOS, that can receive incoming email from the internet. In our lab we use our protectigate.com domain, and a user mailbox john@protectigate.com, who will receive our test email.
1. Starting Setup
We start with a fresh minimal CentOS 8 virtual machine with a single public IP assigned: Hostname: mail.protectigate.com IP: 135.181.86.165
2. Adding public DNS record
One important thing is to create the public "mail" A record for protectigate.com. Our registrar is Godaddy so we add the record there
In the next steps we'll install postfix, configure it, and create our test user "john" on the box which will successfully receive an email from my Gmail mailbox.
3. Install Postfix MTA
yum -y update yum -y install postfix
4. Configure
To configure the postfix service, we need to edit the main configuration file, adding the following content:
a. first, open /etc/postfix/main.cf:
vim /etc/postfix/main.cf
b. Comment out the "inet_interfaces = localhost" part in line 135, and also the "mydestination" part in line 183 as we'll define those later on.
c. Lastly add the following block to the very end of main.cf:
d. When it's all done, enable and start the postfix service
systemctl enable postfix systemctl start postfix
5. Configure firewall
CentOS likely has firewalld as the default firewall already running. We make sure that port 25/tcp is allowed inbound for SMTP traffic:
firewall-cmd --zone=public --permanent --add-port=25/tcp firewall-cmd --reload
6. Create user mailbox
In order for John user to receive emails, first of all it needs to exist. We quickly create "john" user in the system. I skip adding him a password as he will not need to log in, we'll be able to view his incoming mail as root
useradd -s /bin/bash -m john
7. Receive Test message
John is now fully ready to receive incoming emails, so we send an email to john@protectigate.com from our main mailbox.
Postfix stores incoming messages in two locations, both will contain a file with the username (in our case john) with our test email inside when it arrives:
Before email is sent:
After received:
8. Verify
Receiving the message can also be verified by checking the postfix journal logs and the mail queue when sending email messages from our postfix deployment:
# Check logs journalctl -u postfix # View mail queue mailq
Comments