##Prerequisites In order to follow this guide, you should have a Fully Qualified Domain Name pointed at your Ubuntu 14.04 server.
For example:
sd-pmte-stage.spatialdevmo.com points to 54.83.188.204
##Install the Software The installation process of Postfix on Ubuntu 14.04 is easy because the software is in Ubuntu's default package repositories.
Since this is our first operation with apt in this session, we're going to update our local package index and then install the Postfix package:
sudo apt-get update
sudo apt-get install postfix
You will be asked what type of mail configuration you want to have for your server. For our purposes, we're going to choose "Internet Site" because the description is the best match for our server.
Next, you will be asked for the Fully Qualified Domain Name (FQDN) for your server. This is your full domain name (like example.com). Technically, a FQDN is required to end with a dot, but Postfix does not need this. So we can just enter it like:
example.com
Given the FDQN we noted above, we would enter:
sd-pmte-stage.spatialdevmo.com
The software will now be configured using the settings you provided. This takes care of the installation, but we still have to configure other items that we were not prompted for during installation.
##Configure Postfix We are going to need to change some basic settings in the main Postfix configuration file.
Begin by opening this file with root privileges in your text editor:
sudo nano /etc/postfix/main.cf
First, we need to find the myhostname parameter. During the configuration, the FQDN we selected was added to the mydestination parameter, but myhostname remained set to localhost. We want to point this to our FQDN too:
myhostname = sd-pmte-stage.spatialdevmo.com
If you would like to configuring mail to be forwarded to other domains or wish to deliver to addresses that don't map 1-to-1 with system accounts (we do), we can remove the alias_maps parameter and replace it with virtual_alias_maps. We would then need to change the location of the hash to /etc/postfix/virtual:
virtual_alias_maps = hash:/etc/postfix/virtual
As we said above, the mydestination parameter has been modified with the FQDN you entered during installation. This parameter holds any domains that this installation of Postfix is going to be responsible for. It is configured for the FQDN and the localhost.
One important parameter to mention is the mynetworks parameter. This defines the computers that are able to use this mail server. It should be set to local only (127.0.0.0/8 and the other representations). Modifying this to allow other hosts to use this is a huge vulnerability that can lead to extreme cases of spam.
To be clear, the line should be set like this. This should be set automatically, but double check the value in your file:
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
##Configure Additional Email Addresses
We can configure additional email addresses by creating aliases. These aliases can be used to deliver mail to other user accounts on the system.
If you wish to utilize this functionality, make sure that you configured the virtual_alias_maps directive like we demonstrated above. We will use this file to configure our address mappings. Create the file by typing:
sudo nano /etc/postfix/virtual
In this file, you can specify emails that you wish to create on the left-hand side, and username to deliver the mail to on the right-hand side, like this:
[email protected] username1
For our installation, we're going to create a email address and route to a user accounts. We can also set up certain addresses to forward to multiple accounts by using a comma-separated list:
[email protected] ubuntu
Save and close the file when you are finished.
Now, we can implement our mapping by calling this command:
sudo postmap /etc/postfix/virtual
Now, we can reload our service to read our changes:
sudo service postfix restart
##Test sending an email telnet localhost 25 helo localhost mail from: pmte-admin@<your-domain> rcpt to: [email protected] data Subject: pmte admin
Hello,
This is an email sent by using the telnet command.
Your friend,
Me
.
##Prevent sent mail as junk or spam Emails sent often end up being marked as spam. To help avoid this, you can go to wherever you manage your domain name (eg. godaddy) and then configure an SPF record to help make your outgoing email look legit.
On GoDaddy, launch the domain in question spatialdevmo.com, and go to the DNS Zone File. Add a TXT (Text) record:
| Host | TXT Value |
|---|---|
| @ | v=spf1 a mx include:secureserver.net ~all |
| sd-pmte-stage | v=spf1 a mx include:secureserver.net ~all |
Host @ is for the case where you are not using or restricting to a sub-domain.