Install Test And Configure Postfix Mail Server

Setting up Postfix is relatively simple, but can become difficult if you don’t have the correct configuration details. This guide will assume that you have everything sorted out with your MX values and A records. The following guide was tested using postfix-2.6.6-6.el6_5.x86_64 on a centOS server.

Install Postfix

First things first you need to install postfix and dovecot. You may have these applications already installed by default, if this is the case for you then you can skip this step. The command to install these can differ depending on the particular distro of linux you are using. Generally they follow a similar format. The yum command is used for CentOS, Red Hat or any other distro that uses the RPM Package Manager.

yum install postfix
yum remove sendmail

Configure Postfix

The config file (main.cf) for postfix is typically located at “/etc/postfix/main.cf”. Open up this file and either add or uncomment the following lines. Make sure to replace the redacted entries with the actual details of your server. If you don’t add the correct domain and IP address details you will encounter errors.

myhostname = mail.domain.com
mydomain = domain.com
myorigin = $mydomain
inet_interfaces = all
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain, mail.$mydomain
mynetworks = 127.0.0.0/8, [::1]/128, server-ipv4-address, [server-ipv6-address]
relay_domains =
home_mailbox = Maildir/
Test SMTP With Telnet

Telnet is a helpful tool that will allow you to test whether you have successfully set up your server. You will need to make sure you have your domains A records set up correctly in order for smtp.domain.com to be read as a valid address. You can use telnet to send an email to an external email address or a local address. It’s best to test by sending an email to Gmail or another external host. First start by running the telnet command on the smtp address. Note: I will insert the entire output of this process at the end.

telnet smtp.domain.com 25

If everything went ok you will get a message that looks something like the following. Note: the actual addresses may differ e.g. mail.domain.com depending on how you have configured the A records.

Connected to smtp.domain.com.
Escape character is '^]'.
220 mail.domain.com ESMTP Postfix

If everything is well then you can begin the process of sending the email.

mail from:[email protected]

This should return OK. Now you must create the email that you are going to send to the recipient email.

rcpt to:[email protected]

This should also return OK. If the rcpt command returns a “Relay Access Denied” error, you will find a potential solution at the end of the post. If you it went smoothly then you can create the email. Do this by entering the following lines of code 1 after another.

!!NOTE!!
The “.” at the end is important! You need to paste the full stop at the end of the message. When you enter the full stop and click enter it will inform you that it has added the message to the queue.

data

Subject:Test Email

From:[email protected]

Testing postfix

.

quit

The sent message will often show up in your spam box so be sure to check your spam folder before you get worried about it not working correctly.

[root@vps69576 ~]# telnet smtp.domain.com 25
Trying ...
Connected to smtp.domain.com.
Escape character is '^]'.
220 mail.domain.com ESMTP Postfix
mail from:[email protected]
250 2.1.0 Ok
rcpt to:[email protected]
250 2.1.5 Ok
data
354 End data with .
Subject:Test Email From Teln^H^H^H
From:[email protected]
Testing email
.
250 2.0.0 Ok: queued as 73C82700F38
quit
221 2.0.0 Bye
Connection closed by foreign host.

Relay Access Denied Error

I came across this error and it took me a bit of messing around to figure out. Turns out to be quite a simple fix, but this may not always be the solution to this particular error. Hopefully it works for you.

This line will define where mail can be sent from.

"mynetworks = 127.0.0.0/8, [::1]/128, server-ipv4-address, [server-ipv6-address]"

Adding the correct addresses to this variable is important as you may end up getting a “Relay Access Denied” error when you attempt to send mail. You will need to add a few ip addresses to this variable. You will first need to add localhost which is 127.0.0.0/8, then you will need to add the ip addresse(s) of your server. It is best to add both ipv4 and ipv6 as I have ran into issues not having the ipv6 addresses. You must separate all addresses using a comma. ipv4 addresses are written down normally, but ipv6 addresses must be enclosed with square brackets [].

e.g. The following IP addresses apply to this domain

http://yomotherboard.com => 198.50.147.225, [2607:5300:100::3e0]

Related Articles

Related Questions

Could Valid SPF, DKIM, and DMARC Indicate Email Infrastructure Issues?

We've noticed some phishing emails that appear to originate from Truist. What's concerning is that these emails have valid SPF, DKIM, and DMARC checks....

Best Distro for Plex Server and Docker Setup

I'm transitioning from an old PC running Linux Mint with Plex to a mini PC with an 11th Gen i7. I'm planning to set...

Why Does This SPF Rule Quarantine Emails Instead of Rejecting Them?

I've noticed that our transport rule in the Exchange Online Admin Center for handling impersonation emails is set to quarantine emails marked with 'spf=softfail'...

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Latest Tools

Erase Gemini Nano Banana Watermark

Below is a simple content eraser tool. It works very similar to the content aware fill tool that is used in Photoshop. You can...

Keep Your Screen Awake Tool

This simple online stay awake tool prevents your computer screen from going to sleep while you have this page open. It runs entirely in your...

Neural Network Simulation Tool

The Neural Network Visual Builder is an interactive, client-side tool designed to demystify deep learning. It allows users to drag-and-drop neural network layers to...

Ray Trace Simulator – Interactive Optical Ray Tracing Tool

This ray trace simulator lets you visualise how light rays move through an optical system in real time. You can trace beams as they...

Interactive CPU Architecture Simulator

This is an Interactive CPU Architecture Simulator that provides a hands-on, visual learning experience for understanding how a processor executes code. It models a...

AI Image Upscaler

Our AI Image Upscaler allows you to upload any image and instantly increase its resolution using advanced upscaling models. Choose between 2x, 3x or...

Latest Posts

Latest Questions