A earlier model of this tutorial was written by Justin Ellingwood.


Postfix is a well-liked open-source Mail Switch Agent (MTA) that can be utilized to route and ship electronic mail on a Linux system. It’s estimated that round 25% of public mail servers on the web run Postfix.

On this information, we’ll train you stand up and operating shortly with Postfix on an Ubuntu 18.04 server.


With the intention to observe this information, it’s best to have entry to a non-root person with sudo privileges. You possibly can observe our Ubuntu 18.04 preliminary server setup information to create the required person.

With the intention to correctly configure Postfix, you will want a Absolutely Certified Area Title pointed at your Ubuntu 18.04 server. You could find assistance on establishing your area identify with DigitalOcean by following this information. Should you plan on accepting mail, you will want to be sure you have an MX file pointing to your mail server as nicely.

For the needs of this tutorial, we are going to assume that you’re configuring a bunch that has the FQDN of mail.instance.com.

Step 1 — Set up Postfix

Postfix is included in Ubuntu’s default repositories, so set up is straightforward.

To start, replace your native apt package deal cache after which set up the software program. We might be passing within the DEBIAN_PRIORITY=low environmental variable into our set up command with a view to reply some further prompts:

  • sudo apt replace
  • sudo DEBIAN_PRIORITY=low apt set up postfix

Use the next info to fill in your prompts appropriately on your atmosphere:

  • Basic kind of mail configuration?: For this, we are going to select Web Web site since this matches our infrastructure wants.
  • System mail identify: That is the bottom area used to assemble a sound electronic mail tackle when solely the account portion of the tackle is given. As an example, the hostname of our server is mail.instance.com, however we most likely need to set the system mail identify to instance.com in order that given the username user1, Postfix will use the tackle [email protected].
  • Root and postmaster mail recipient: That is the Linux account that might be forwarded mail addressed to [email protected] and [email protected]. Use your main account for this. In our case, sammy.
  • Different locations to simply accept mail for: This defines the mail locations that this Postfix occasion will settle for. If you could add another domains that this server might be liable for receiving, add these right here, in any other case, the default ought to work high-quality.
  • Power synchronous updates on mail queue?: Since you might be possible utilizing a journaled filesystem, settle for No right here.
  • Native networks: It is a record of the networks that your mail server is configured to relay messages for. The default ought to work for many situations. Should you select to switch it, be certain to be very restrictive regarding the community vary.
  • Mailbox dimension restrict: This can be utilized to restrict the scale of messages. Setting it to “0” disables any dimension restriction.
  • Native tackle extension character: That is the character that can be utilized to separate the common portion of the tackle from an extension (used to create dynamic aliases).
  • Web protocols to make use of: Select whether or not to limit the IP model that Postfix helps. We’ll choose “all” for our functions.

To be express, these are the settings we’ll use for this information:

  • Basic kind of mail configuration?: Web Web site
  • System mail identify: instance.com (not mail.instance.com)
  • Root and postmaster mail recipient: sammy
  • Different locations to simply accept mail for: $myhostname, instance.com, mail.instance.com, localhost.instance.com, localhost
  • Power synchronous updates on mail queue?: No
  • Native networks: [::ffff:]/104 [::1]/128
  • Mailbox dimension restrict: 0
  • Native tackle extension character: +
  • Web protocols to make use of: all

If you could ever return to re-adjust these settings, you are able to do so by typing:

  • sudo dpkg-reconfigure postfix

The prompts might be pre-populated along with your earlier responses.

When you’re completed, we will now do a bit extra configuration to arrange our system how we might prefer it.

Step 2 — Tweak the Postfix Configuration

Subsequent, we will alter some settings that the package deal didn’t immediate us for.

To start, we will set the mailbox. We’ll use the Maildir format, which separates messages into particular person information which might be then moved between directories primarily based on person motion. The opposite choice is the mbox format (which we cannot cowl right here) which shops all messages inside a single file.

We’ll set the home_mailbox variable to Maildir/ which is able to create a listing construction beneath that identify inside the person’s house listing. The postconf command can be utilized to question or set configuration settings. Configure home_mailbox by typing:

  • sudo postconf -e 'home_mailbox= Maildir/'

Subsequent, we will set the situation of the virtual_alias_maps desk. This desk maps arbitrary electronic mail accounts to Linux system accounts. We’ll create this desk at /and many others/postfix/digital. Once more, we will use the postconf command:

  • sudo postconf -e 'virtual_alias_maps= hash:/and many others/postfix/digital'

Step 3 — Map Mail Addresses to Linux Accounts

Subsequent, we will arrange the digital maps file. Open the file in your textual content editor:

  • sudo nano /and many others/postfix/digital

The digital alias map desk makes use of a quite simple format. On the left, you’ll be able to record any addresses that you simply want to settle for electronic mail for. Afterwards, separated by whitespace, enter the Linux person you need that mail delivered to.

For instance, if you want to simply accept electronic mail at [email protected] and [email protected] and wish to have these emails delivered to the sammy Linux person, you can arrange your file like this:

/and many others/postfix/digital

[email protected]instance.com sammy
[email protected]instance.com sammy

After you’ve got mapped all the addresses to the suitable server accounts, save and shut the file.

We will apply the mapping by typing:

  • sudo postmap /and many others/postfix/digital

Restart the Postfix course of to ensure that all of our modifications have been utilized:

  • sudo systemctl restart postfix

Step 4 — Modify the Firewall

In case you are operating the UFW firewall, as configured within the preliminary server setup information, we’ll have to permit an exception for Postfix.

You possibly can permit connections to the service by typing:

The Postfix server element is put in and prepared. Subsequent, we are going to arrange a consumer that may deal with the mail that Postfix will course of.

Step 5 — Establishing the Setting to Match the Mail Location

Earlier than we set up a consumer, we must always be certain our MAIL environmental variable is ready appropriately. The consumer will examine this variable to determine the place to search for person's mail.

To ensure that the variable to be set no matter the way you entry your account (by means of ssh, su, su -, sudo, and many others.) we have to set the variable in a couple of totally different areas. We'll add it to /and many others/bash.bashrc and a file inside /and many others/profile.d to ensure every person has this configured.

So as to add the variable to those information, kind:

  • echo 'export MAIL=~/Maildir' | sudo tee -a /and many others/bash.bashrc | sudo tee -a /and many others/profile.d/mail.sh

To learn the variable into your present session, you'll be able to supply the /and many others/profile.d/mail.sh file:

  • supply /and many others/profile.d/mail.sh

Step 6 — Set up and Configure the Mail Shopper

With the intention to work together with the mail being delivered, we are going to set up the s-nail package deal. It is a variant of the BSD xmail consumer, which is feature-rich, can deal with the Maildir format appropriately, and is usually backwards suitable. The GNU model of mail has some limitations, akin to all the time saving learn mail to the mbox format whatever the supply format.

To put in the s-nail package deal, kind:

We must always alter a couple of settings. Open the /and many others/s-nail.rc file in your editor:

In direction of the underside of the file, add the next choices:

/and many others/s-nail.rc

. . .
set emptystart
set folder=Maildir
set file=+despatched

This may permit the consumer to open even with an empty inbox. It's going to additionally set the Maildir listing to the interior folder variable after which use this to create a despatched mbox file inside that, for storing despatched mail.

Save and shut the file when you find yourself completed.

Step 7 — Initialize the Maildir and Take a look at the Shopper

Now, we will take a look at the consumer out.

Initializing the Listing Construction

The simplest method to create the Maildir construction inside our house listing is to ship ourselves an electronic mail. We will do that with the s-nail command. As a result of the despatched file will solely be out there as soon as the Maildir is created, we must always disable writing to that for our preliminary electronic mail. We will do that by passing the -Snorecord choice.

Ship the e-mail by piping a string to the s-nail command. Modify the command to mark your Linux person because the recipient:

  • echo 'init' | s-nail -s 'init' -Snorecord sammy

You might get the next response:


Cannot canonicalize "/house/sammy/Maildir"

That is regular and will solely seem when sending this primary message. We will verify to ensure the listing was created by on the lookout for our ~/Maildir listing:

You must see the listing construction has been created and {that a} new message file is within the ~/Maildir/new listing:


/house/sammy/Maildir/: cur new tmp /house/sammy/Maildir/cur: /house/sammy/Maildir/new: 1463177269.Vfd01I40e4dM691221.mail.instance.com /house/sammy/Maildir/tmp:

It seems to be like our mail has been delivered.

Managing Mail with the Shopper

Use the consumer to verify your mail:

You must see your new message ready:


s-nail model v14.8.6. Kind ? for assist. "/home/sammy/Maildir": 1 message 1 new >N 1 [email protected] Wed Dec 31 19:00 14/369 init

Simply hitting ENTER ought to show your message:


[-- Message 1 -- 14 lines, 369 bytes --]: From [email protected] Wed Dec 31 19:00:00 1969 Date: Fri, 13 Could 2016 18:07:49 -0400 To: [email protected] Topic: init Message-Id: <[email protected]> From: [email protected] init

You will get again to your message record by typing h, after which ENTER:


s-nail model v14.8.6. Kind ? for assist. "/home/sammy/Maildir": 1 message 1 new >R 1 [email protected] Wed Dec 31 19:00 14/369 init

Since this message is not very helpful, we will delete it with d, after which ENTER:

Give up to get again to the terminal by typing q after which ENTER:

Sending Mail with the Shopper

You possibly can take a look at sending mail by typing a message in a textual content editor:

Inside, enter some textual content you'd wish to electronic mail:


Whats up,

It is a take a look at.  Please affirm receipt!

Utilizing the cat command, we will pipe the message to the s-nail course of. This may ship the message as your Linux person by default. You possibly can alter the "From" discipline with the -r flag if you wish to modify that worth to one thing else:

  • cat ~/test_message | s-nail -s 'Take a look at electronic mail topic line' -r from_field_account person@electronic mail.com

The choices above are:

  • -s: The topic line of the e-mail
  • -r: An non-obligatory change to the "From:" discipline of the e-mail. By default, the Linux person you might be logged in as might be used to populate this discipline. The -r choice permits you to override this.
  • [email protected] mail.com: The account to ship the e-mail to. Change this to be a sound account you may have entry to.

You possibly can view your despatched messages inside your s-nail consumer. Begin the interactive consumer once more by typing:

Afterwards, view your despatched messages by typing:

You possibly can handle despatched mail utilizing the identical instructions you utilize for incoming mail.


You must now have Postfix configured in your Ubuntu 18.04 server. Managing electronic mail servers is usually a powerful process for starting directors, however with this configuration, it's best to have fundamental MTA electronic mail performance to get you began.

Docker Information: Dockerizing Python Django Software

Previous article

How Do SIM Playing cards Work?

Next article

You may also like


Leave a reply

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

More in Linux