Applicability: Mail service is needed for most small business websites. Email forwarding is a very simple alternative to the complexity of hosting and maintaining a web based mail server. Email forwarding allows you to have email addresses that are based on your business' domain name just like your business has it's own email server. An example business email is as follows:
greg@yourbusinessdomain.com.
If only a small number of email addresses are needed and the business is willing to place the email traffic on a third party server, Email forwarding can be a quick and effective solution. If you choose to use Email forwarding, email sent to your business web domain will be forwarded to a third party email server such as Gmail or your own business network service provider such as Verizon. The best part about using Gmail or Verizon for your email is that the service is either free or included in a service you have already purchased.
Required Environment: This guide assumes that you are installing postfix on a computer running Ubuntu linux. The simplest installation is to install postfix on the same system that hosts your business website so the computer will already be running your business web server. Some domain name providers such as Enom will forward emails for free and if your business is currently using one of those vendors, you will not need to install postfix. If you don't need postfix, simply create your email accounts as shown in the guide and then follow your domain name service providers instructions to forward your email.
Installation Process: The basic steps for forwarding email are as follows:
Creating Email Accounts: You must obtain at least one email account on a third party email server. You may have multiple email addresses forwarded to a single email account or to multiple accounts. The names of the email accounts you create will not be visible when you use your business email so they can be any unique name you choose. Here are some examples that we will use in this guide:
lucralogic@verizon.net, mybusiness@gmail.com
Simply follow the service providers instructions to create an email account just as you would for any other email account.
Create an MX Record: Logon to the domain name server for your business domain and create a MX record if one is not already present. The following is an example MX record:
Next you should check that the MX record is correct and points to your business domain with the dig command and mx option. Just type the following from your local computers terminal bash shell:
You should see your MX record in the ANSWER SECTION as shown above. Next you should check what IP address of the MX record with the dig command and the a option:
In the ANSWER SECTION the IP address for mail.lucralogic.com is shown. The IP address should be the IP address of your domain.
Install postfix: First you need to go to the terminal program of the computer that hosts your business domain. In most cases this means that you would just SSH to the bash shell of the host computer. To SSH to your host computer you will need your user name and the ip address of your host computer. For the simplest installations you would just type "ssh username@ipAddress" and then enter the password when prompted. When the logon is complete, you should see a user prompt that typically looks like "user@hostname:~:". To install postfix on Ubuntu simply use apt-get as shown below:
The package manager will first show a help screen that describes the types of installations that you can select. You need to select OK at the bottom of the help screen to advance to the actual installation screen. When the installation screen pops up, select the “No configuration” type of mail configuration and then select OK at the bottom of the screen. The package manager will complete the installation and the next step is to configure some files.
Configure postfix: First you need to create the main.cf file and postfix installs with an example file that you can just copy and modify as shown below:
Now you need to add three lines to the main.cf file and you can do that using your favorite editor. I use vi and you will need to use sudo as shown below:
Go to the end of the file and after entering insert mode, add the following lines but replace my example domain and hostname with your domain and host name. Note that you can add as many virtual domains as you want, just as long as you have created an MX record for each.
virtual_alias_domains = lucralogic.com otherdomains.com
virtual_alias_maps = hash:/etc/postfix/virtual
myhostname = hostname.lucralogic.com
After you have saved your changes to the main.cf file you will need to create the virtual file and add your email routing information. First, create the virtual file by starting the editor as shown below:
Next, add the following lines to the virtual file to define the desired routing of the emails and replace the email addresses with your companies addresses:
@lucralogic.com lucralogic@verizon.net mybusiness@gmail.com
In the example shown above, all emails to the domain lucralogic will be forwarded to both lucralogic@verizon.net and mybusiness@gmail.com. In the following example the email for greg is sent to verizon.net and the email for tim is sent to gmail.com
greg@lucralogic.com lucralogic@verizon.net
tim@otherdomains.com mybusiness@gmail.com
After you have saved and exited the virtual file you should convert your file to Berkley DB format with postmap as shown below:
The postmap command will create the file virtual.db so you can check to see if the file was created. The last step is to restart postfix with the following command:
Set Your Firewall to Allow SMTP on Port 25: When you first setup your server you probably configured the firewall to drop all inbound traffic except for those bound for the specific services you implemented. If you have implemented a web server you would typically allow traffic to the following ports that are standard for the following services:
Port | Protocol | Service | Description |
---|---|---|---|
80 | tcp | HTTP | Web Page Server |
8080 | tcp | HTTP | Alternate HTTP (Typically Apache Tomcat) |
443 | tcp | HTTPS | Secure Web Pages |
22 | tcp | SSH | Secure Shell Interface |
- | icmp | echo-request | Allows Ping |
Typically, email is transferred from your email client on your computer through a series of servers and clients until it is delivered to the destination client at the email address you specified. When Postfix is forwarding email it is providing the function of the Mail Transfer Agent (MTA). All transfers to and from the MTA are transacted on port 25. If your firewall is configured to block port 25 you must make the following addition to allow incoming traffic on port 25. Edit the following file and add the following rule to allow inbound traffic to port 25.
File: /etc/iptables.firewall.rules
Add this rule:
# Allow inbound traffic to port 25 for smtp forwarding
-A INPUT -p tcp –dport 25 -j ACCEPT
Typically the firewall will not be configured to prohibit outbound traffic so port 25 will not be blocked in the outbound direction. Activate the firewall rules by entering the following:
You can check to see if your firewall is now setup with the following command:
Test your installation: To test your installation go to an external email account and send an email to your new business email address such as greg@lucralogic.com. If everything is working you should receive an email in your third party email. In this example the email will be forwarded to your lucralogic@verizon.net account. You can set up an account in your email client in windows, linux, OSX, or other operating system to send your mail from your business email address. If you have an issue you can check the email routing at any time with the following command:
You can also check for problems reported by postfix in the following files:
/var/log/mail.log | All log messages |
/var/log/mail.err | All error messages |
/var/log/mail.warn | All warning messages |