How to Set Up a Postfix Mail Server on Debian

E-mail is likely one of the most elementary messaging strategies used because the growth of the web. This has led to the event of many messaging instruments and protocols. There are protocols for the suitable operation of techniques with totally different architectures.

E-mail servers carry out duties comparable to not shedding consumer e-mails, and helping customers in accessing their e-mails after they’re on-line. The instruments that present e-mail transmission on native intranets and the web are referred to as Mail Transfer Agents (MTA).


Here’s how to set up and arrange a Postfix mail server on a Debian Linux set up.

Step 1: Postfix Mail Server Installation on Debian

In many circumstances, Postfix comes to the fore due to its ease of use, few settings, and the excessive variety of makes use of. Use the next command to set up Postfix on your Debian-based Linux distribution:

Internet Sitesudo apt set up postfix

If you’ve got Sendmail put in on your system, it will be higher to uninstall it earlier than putting in Postfix.

sudo apt take away sendmail

During set up, Postfix will ask you some questions. Select Internet Site for the primary incoming request and enter the area identify you need within the second immediate.

Like most Linux software program, Postfix shops its settings in information. This is nice as you may make any adjustments you need to Postfix by merely modifying textual content information. Postfix settings are usually positioned within the file. Just to be on the secure aspect, you need to all the time create a backup of the default file.

Step 2: Configurations for Postfix Mail Server

First of all, open the file with a textual content editor of your alternative and alter its content material as you need. There is a lot of primary info contained in the file, comparable to mydomain (area identify of the machine) and myhostname (full identify of the SMTP server). Tweak the settings to make the server work. You can refer to the instance under to get an thought.

vim /and so forth/postfix/

Step 3: Sending Mail With Postfix

To ship your first mail utilizing the Postfix server, use the instructions under. These instructions are for including your IP handle and area identify to the hosts file.

hostnamectl set-hostname
echo " fatih.lab mail.fatih.lab" >> /and so forth/hosts

Reboot your system to be sure the settings take impact. After the reboot, test the contents of your hostname file with the command under.

hostname && cat /and so forth/hostname && hostname -s

Then test your port quantity utilizing the next command to be sure all the pieces is so as:

netstat -tlpn

Now you’ll be able to compose your first message and see how issues are going.

Send your first electronic mail with the command under:

echo "my first mail content material" | mail -s "Hello Postfix" root

After this step, open the Maildir folder laid out in the file to confirm if all the pieces is ok. If all went nicely, the e-mail you despatched must be right here.

cat /Maildir/new/[Press Tab]

Step 4: IMAP and Dovecot Configuration

If you’ve got ever had an electronic mail server service, you’ve got most likely heard of electronic mail protocols earlier than. These protocols are POP and IMAP. The alternative you make has a enormous impression on your sending, receiving, and different electronic mail transmission flows. While POP (Post Office Protocol) is the preferred sort of electronic mail protocol, IMAP (Internet Message Access Protocol) is the protocol of alternative for many customers as of late.

Below you will see that an instance of sending mail with Postfix and IMAP. But earlier than that, it is necessary to have no less than a superficial information of IMAP.

IMAP acts as a bridge between your electronic mail shopper and your electronic mail server. E-mail servers enable you to ship and obtain emails. However, IMAP permits you to protect your emails on the server till you take away them manually. When you log in to an electronic mail shopper, comparable to Gmail or Outlook, the shopper makes use of IMAP to join to the e-mail server.

Also, IMAP has many benefits. For instance, you’ll be able to entry your electronic mail messages from as many various units as you need and from anyplace. It additionally downloads the related message solely if you click on on it.

Email attachments usually are not routinely downloaded with IMAP. So you’ll be able to test your messages a lot sooner and have management over which file attachments you need to open.

As the world strikes an increasing number of in direction of cellular, IMAP naturally turns into extra in style. The proliferation of smartphones, laptops, tablets, and different units is making the demand for IMAP extra intense than ever earlier than.

Configuring Dovecot

With Dovecot, it’s potential to ship community mail transfers utilizing POP3 or IMAP. The very first thing you want to do to get it working is to set up it on your system with the next command:

sudo apt set up dovecot-core dovecot-imapd

After the set up, there might be some information within the /and so forth/dovecot folder. You want to make numerous changes to these information and configure Dovecot.

First, you want to set up a connection between your Maildir folder and Dovecot. The mail_location line specifies the folder to retailer the mails. Replace the expression right here with Maildir as follows. To do that, open the 10-mail.conf file with any editor you need.

vim /and so forth/dovecot/conf.d/10-mail.conf

And change the road beginning with mail_location to:

mail_location = maildir:~/Maildir

Now you’ll set up a connection between Postfix and Dovecot. For this, open the 10-master.conf file in the identical manner and alter the codes under the Postfix smtp-auth remark:

vim /and so forth/dovecot/conf.d/10-master.conf

Change the next traces within the file:

unix_listener /var/spool/postfix/personal/auth {
mode = 0666
consumer = postfix
group = postfix

Dovecot works on port 143 by default. To test this, restart the dovecot service and test the port quantity with the command under:

netstat -tlpn

Now that every one is nicely, it is time to ship a actual electronic mail. For this, create a new consumer utilizing the instructions under:

adduser testuser

Then join to port 25 utilizing the nc command.

nc localhost 25

The contents of your terminal login display might differ barely however that’s regular. You can use Ctrl + C to exit and retry when you stumble upon any error. The command you need to use at this stage is:

ehlo localhost

You are actually on the stage of modifying the e-mail content material. The command construction you want to enter at this stage is:

mail from: root
rcpt to: testuser
topic: testsubject
my mail content material

There is one final place to test whether or not the e-mail transmission was profitable. By configuration, this electronic mail wants to be within the Maildir folder. To do that, test whether or not the e-mail you despatched exists on this folder with the next command:

cat /house/testuser/Maildir/new/[Press Tab]

As you’ll be able to see, with Dovecot IMAP and Postfix, you may have efficiently despatched the specified content material to testuser.

Why Use Postfix on Linux Servers?

As you’ll be able to see from the examples, utilizing Postfix could be very sensible and simple. Postfix could be very versatile for mail server directors and builders. Moreover, it is suitable with many instruments comparable to SQL, MySQL, Cyrus, LDAP, SASL, TSL, and SSL. Compared to different MTAs, it performs higher even on techniques with heavy site visitors and a number of other customers.

Postfix runs fairly easily on not solely Linux however Unix and Windows as nicely. Even expertise firms with high-tech servers comparable to Microsoft, Google, and Amazon have used Postfix in lots of areas. Moreover, it’s rather more profitable by way of safety, particularly in comparison to Sendmail. For these causes, the Postfix mail structure continues to be most well-liked by mail server directors even after 20 years.

Related Posts