Views: 565
Back to configuring a simpler version of Postfix, for small biz and Hipaa
Step 1: Install Postfix
Postfix is included in Ubuntu’s default repositories, so installation is incredibly simple.
To begin, update your local
apt
package cache and then install the software. We will be passing in theDEBIAN_PRIORITY=low
environmental variable into our installation command in order to answer some additional prompts:
- sudo apt-get update
- sudo DEBIAN_PRIORITY=low apt-get install postfix
Use the following information to fill in your prompts correctly for your environment:
- General type of mail configuration?: For this, we will choose Internet Site since this matches our infrastructure needs.
- System mail name: This is the base domain used to construct a valid email address when only the account portion of the address is given. For instance, the hostname of our server is
mail.example.com
, but we probably want to set the system mail name toexample.com
so that given the usernameuser1
, Postfix will use the addressuser1@example.com
.- Root and postmaster mail recipient: This is the Linux account that will be forwarded mail addressed to
root@
andpostmaster@
. Use your primary account for this. In our case, sammy.- Other destinations to accept mail for: This defines the mail destinations that this Postfix instance will accept. If you need to add any other domains that this server will be responsible for receiving, add those here, otherwise, the default should work fine.
- Force synchronous updates on mail queue?: Since you are likely using a journaled filesystem, accept No here.
- Local networks: This is a list of the networks that your mail server is configured to relay messages for. The default should work for most scenarios. If you choose to modify it, make sure to be very restrictive in regards to the network range.
- Mailbox size limit: This can be used to limit the size of messages. Setting it to “0” disables any size restriction.
- Local address extension character: This is the character that can be used to separate the regular portion of the address from an extension (used to create dynamic aliases).
- Internet protocols to use: Choose whether to restrict the IP version that Postfix supports. We’ll pick “all” for our purposes.
To be explicit, these are the settings we’ll use for this guide:
- General type of mail configuration?: Internet Site
- System mail name: example.com (not mail.example.com)
- Root and postmaster mail recipient: sammy
- Other destinations to accept mail for: $myhostname, example.com, mail.example.com, localhost.example.com, localhost
- Force synchronous updates on mail queue?: No
- Local networks: 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
- Mailbox size limit: 0
- Local address extension character: +
- Internet protocols to use: all
If you need to ever return to re-adjust these settings, you can do so by typing:
- sudo dpkg-reconfigure postfix
The prompts will be pre-populated with your previous responses.
When you are finished, we can now do a bit more configuration to set up our system how we’d like it.
Step 2: Tweak the Postfix Configuration
Next, we can adjust some settings that the package did not prompt us for.
To begin, we can set the mailbox. We will use the Maildir format, which separates messages into individual files that are then moved between directories based on user action. The other option is the mbox format (which we won’t cover here) which stores all messages within a single file.
We will set the
home_mailbox
variable toMaildir/
which will create a directory structure under that name within the user’s home directory. Thepostconf
command can be used to query or set configuration settings. Configurehome_mailbox
by typing:
- sudo postconf -e ‘home_mailbox= Maildir/’
Next, we can set the location of the
virtual_alias_maps
table. This table maps arbitrary email accounts to Linux system accounts. We will create this table at/etc/postfix/virtual
. Again, we can use thepostconf
command:
- sudo postconf -e ‘virtual_alias_maps= hash:/etc/postfix/virtual’
Step 5: Setting up the Environment to Match the Mail Location
Before we install a client, we should make sure our
In order for the variable to be set regardless of how you access your account (through
ssh
,su
,su -
,sudo
, etc.) we need to set the variable in a few different locations. We’ll add it to/etc/bash.bashrc
and a file within/etc/profile.d
to make sure each user has this configured.To add the variable to these files, type:
- echo ‘export MAIL=~/Maildir’ | sudo tee -a /etc/bash.bashrc | sudo tee -a /etc/profile.d/mail.sh
To read the variable into your current session, you can source the
/etc/profile.d/mail.sh
file:
- source /etc/profile.d/mail.sh
Step 7: Initialize the Maildir and Test the Client
Now, we can test the client out.
Initializing the Directory Structure
The easiest way to create the Maildir structure within our home directory is to send ourselves an email. We can do this with the mail
command. Because the sent
file will only be available once the Maildir is created, we should disable writing to that for our initial email. We can do this by passing the -Snorecord
option.
Send the email by piping a string to the mail
command. Adjust the command to mark your Linux user as the recipient:
- echo ‘init’ | mail -s ‘init’ -Snorecord sammy
Introduction Postfix is a popular open-source Mail Transfer Agent (MTA) that can be used to route and deliver email on a Linux system. It is estimated that around 25% of public mail servers on the internet run Postfix. In this guide, we’ll teach you how to get up and running quickly with Postfix on an Ubuntu 16.04 server. Prerequisites In order to follow this guide, you should have access to a non-root user with sudo privileges. You can follow our Ubuntu 16.04 initial server setup guide to create the neces
Source: How To Install and Configure Postfix on Ubuntu 16.04 | DigitalOcean