Build Your Own Email Server On Ubuntu: Basic Postfix Setup
Build Your Own Email Server On Ubuntu: Basic Postfix Setup
I’m confident to say that this is the best tutorial series about
building email server from scratch on the Internet. Not only
will you have a working email server, but also you will have
a much better understanding about how email works. This
tutorial series is divided into 9 parts.
About Postfix
Prerequisites
mail.linuxbabe.com
hostname -f
MX record
Note that when you create the MX record, you should enter
@ or your apex domain name in the name field like below.
An apex domain name is a domain name without any sub-
domain.
A record
AAAA record
If your server uses IPv6 address, it’s also a good idea to add
AAAA record for mail.yourdomain.com .
mail.linuxbabe.com <IPv6-addre
ss>
PTR record
To check the PTR record for an IP address, you can use the
following command.
or
host <IP>
Because you get IP address from your hosting provider, not
from your domain registrar, so you must set PTR record for
your IP address in your hosting provider’s control panel. Its
value should be your mail server’s hostname: mail.your-
domain.com . If your server uses IPv6 address, then add
PTR record for your IPv6 address as well.
To edit the reverse DNS record for your Hostwinds VPS, log
into Hostwinds client area, select Domains -> Manage
rDNS , Then you can edit the reverse DNS record for both
IPv4 and IPv6 addresses.
Installing Postfix
Next, enter your domain name for the system mail name, i.e.
the domain name after @ symbol. For example, my email
address is [email protected], so I entered
linuxbabe.com for the system mail name. This domain
name will be appended to addresses that doesn’t have a
domain name specified.
Once installed, Postfix will be automatically started and a
/etc/postfix/main.cf file will be generated. Now we
can check Postfix version with this command:
postconf mail_version
mail_version = 3.4.10
Output:
/usr/sbin/postalias
/usr/sbin/postcat
/usr/sbin/postconf
/usr/sbin/postdrop
/usr/sbin/postfix
/usr/sbin/postfix-add-filter
/usr/sbin/postfix-add-policy
/usr/sbin/postkick
/usr/sbin/postlock
/usr/sbin/postlog
/usr/sbin/postmap
/usr/sbin/postmulti
/usr/sbin/postqueue
/usr/sbin/postsuper
/usr/sbin/posttls-finger
/usr/sbin/qmqp-sink
/usr/sbin/qmqp-source
/usr/sbin/qshape
/usr/sbin/rmail
/usr/sbin/sendmail
/usr/sbin/smtp-sink
/usr/sbin/smtp-source
Then we can use nmap to scan open ports on our server. Run
the following command on a separate computer such as your
personal computer. (I assume you are reading this tutorial on
a Linux computer.) Replace your-server-ip with actual
IP.
You can see from the above screenshot that TCP port 25 is
open on my server.
nmap can be installed on Linux with one of the following
commands, depending on your Linux distro.
telnet gmail-smtp-in.l.google.com 25
Trying 74.125.68.26...
Connected to gmail-smtp-in.l.google.c
om.
Escape character is '^]'.
220 mx.google.com ESMTP y22si1641751p
ll.208 - gsmtp
Trying 2607:f8b0:400e:c06::1a...
Trying 74.125.195.27...
telnet: Unable to connect to remote h
ost: Connection timed out
Also, you can try to reply to this test email to see if Postfix
can receive email messages. It’s likely that emails sent from
your domain are labeled as spam. Don’t worry about it now.
We will solve this problem in later parts of this tutorial
series.
postconf mail_spool_directory
mail [email protected]
Enter the subject line and the body text. To tell mail that
you have finished writing, press Ctrl+D and mail will send
this email message for you.
mail
Here’s how to use the mail program to manage your
mailbox.
Output:
message_size_limit = 10240000
Output:
mailbox_size_limit = 0
myhostname = mail.yourdomain.com
Save and close the file. (To save a file in Nano text editor,
press Ctrl+O , then press Enter to confirm. To exit, press
Ctrl+X .) Restart Postfix for the change to take effect.
root: username
sudo newaliases
postconf inet_protocols
Output:
inet_protocols = all
Next Step
MX Record port 25 postfix system time