Search The Hostwinds Guides Knowledge Base

Install Postfix and s-nail on Ubuntu (18.04)

Share This Article

In this guide, we will go over how to install and configure Postfix and s-nail to send and receive mail on your Ubuntu 18.04 server. For this guide, you will need to connect to your server using SSH as root or a superuser. In order to continue, a Hostwinds Cloud, VPS or Dedicated Server should be ready for use.

As always, before making any changes to your server or continuing with this guide, we highly suggest you have a good working backup of your server.

As always, make sure your server is up to date.

Step 1: Install and configure Postfix

The first step is to install Postfix. We are using DEBIAN_PRIORITY=low in order to see more options during installation.

Type the following into the terminal

Next, we will want to configure some options:

Postfix configuration, Internet Site
Choose Internet Site.

 

Postfix configuration, entering a fully qualified domain name
Enter a fully qualified domain name.

 

Postfix configuration, choose root and postmaster mail recipient
Enter the root and postmaster mail recipient

 

postfix configuration,  choosing other locations  to accept mail for
Enter other destinations to accept mail for. The defaults should be fine.

 

Do not force synchronous updates on mail queue
You are likely using a journaled filesystem, so you can select “no”.

 

Specify Local Networks
This screen will ask you to specify your local networks. You can leave this as the default.

 

Set mailbox size limit
Specify the mailbox size limit in bytes. Setting it as 0 will impose no limitations.

 

set a local address extention character
Set the character that will be used to designate address extentions.

 

Select internet protocols to use
Here, we are setting which internet protocols to use with Postfix. You can leave this as all.

 

 

Step 2: Tweak Postfix

There are some items that were not set up during the installation of the package that we will be addressing below.

We will be creating a directory structure under the user’s home directory. Set this up by typing

We will then specify where the virtual_alias_maps table will be stored:

We are now going to set up the virtual maps file. You can open this in your favorite text editor. In this tutorial, we are going to use nano.

The formatting for this file is that the address on the left is an email address you would like to receive mail for, then a blank space, then the Linux user that you would like the mail delivered to. Your file with your email addresses and Linux users will look something like the following:

Save the file and exit the editor, and apply our mapping changes by typing

The next step is to allow Postfix through the firewall. In this example, we are using ufw, and you can use the following command:

Step 3: Installing s-nail

A prerequisite of installing a mail client is going to be setting the MAIL variable. The mail client checks this variable to figure out where to get the user’s mail from. For this to work no matter how the user accesses their account, you will need to set this variable in multiple locations:

You will also want to source the /etc/profile.d/mail.sh file into your current session:

Next, we will install the s-nail package:

After this is complete, open /etc/s-nail.rc in your text editor of choice:

At the bottom of the file, add the following lines:

Step 4: Initialize The Directory Structure

The best way to create the Maildir structure is to send yourself an email. You will use the s-nail command with the -Snorecord option. Change the following command to match the user you are wanting to use:

To view all commands possible, you can view the help page for s-nail:

Related Articles