• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to secondary sidebar
OpenTechTips

OpenTechTips

Comprehensive IT Guides for Pros and Enthusiasts

MENUMENU
  • HOME
  • ALL TOPICS
    • Exchange
    • InfoSec
    • Linux
    • Networking
    • Scripting
      • PowerShell
    • SSL
    • Tools
    • Virtualization
    • Web
    • Windows
  • ABOUT
  • SUBSCRIBE
Home » Install Postfix on CentOS for Internet email traffic

Install Postfix on CentOS for Internet email traffic

September 4, 2020 - by Zsolt Agoston - last edited on September 21, 2020

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

Install Postfix on CentOS for Internet email traffic

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

Install Postfix on CentOS for Internet email traffic

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.

Note that in different postfix versions these lines might be located in different lines, you'll need to search for them.

Install Postfix on CentOS for Internet email traffic

c. Lastly add the following block to the very end of main.cf:

myhostname = mail
mydomain = protectigate.com
myorigin = $mydomain
mydestination = $mydomain, $myhostname, localhost
inet_interfaces = all
inet_protocols = all
mynetworks = 0.0.0.0/0
disable_dns_lookups = yes
Install Postfix on CentOS for Internet email traffic

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:

/var/mail
/var/spool/mail

Before email is sent:

Install Postfix on CentOS for Internet email traffic

After received:

Install Postfix on CentOS for Internet email traffic

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

Reader Interactions

Comments Cancel reply

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

Primary Sidebar

Tools

Secondary Sidebar

CONTENTS

  • 1. Starting Setup
  • 2. Adding public DNS record
  • 3. Install Postfix MTA
  • 4. Configure
  • 5. Configure firewall
  • 6. Create user mailbox
  • 7. Receive Test message
  • Before email is sent:
  • After received:
  • 8. Verify

  • Terms of Use
  • Disclaimer
  • Privacy Policy
Manage your privacy

To provide the best experiences, we and our partners use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us and our partners to process personal data such as browsing behavior or unique IDs on this site and show (non-) personalized ads. Not consenting or withdrawing consent, may adversely affect certain features and functions.

Click below to consent to the above or make granular choices. Your choices will be applied to this site only. You can change your settings at any time, including withdrawing your consent, by using the toggles on the Cookie Policy, or by clicking on the manage consent button at the bottom of the screen.

Functional Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes. The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.
Statistics

Marketing

Features
Always active

Always active
Manage options Manage services Manage {vendor_count} vendors Read more about these purposes
Manage options
{title} {title} {title}
Manage your privacy
To provide the best experiences, we use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us to process data such as browsing behavior or unique IDs on this site. Not consenting or withdrawing consent, may adversely affect certain features and functions.
Functional Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes. The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.
Statistics

Marketing

Features
Always active

Always active
Manage options Manage services Manage {vendor_count} vendors Read more about these purposes
Manage options
{title} {title} {title}