Postfix is widely used Mail Transfer Agent (MTA) server, which provides to send, receive and forward emails over network. This tutorial will help you to configure your Postfix server to forward emails.
Install Postfix MTA
We are assuming that you already have postfix installed and configured on your system. Or you can use following commands to install Postfix on Linux box according to your operating system.
On Debian Based Systems
$ sudo apt-get update $ sudo apt-get install postfix
On RHEL Based Systems
# yum install postfix
On OpenSUSE Systems
# zypper in postfix
After installation make sure Postfix is running on your system. Default postfix used standard port 25. Use the following commands to check that your system is listening on port 25 or not.
# netstat -tulpn | grep 25 tcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN 4398/master tcp6 0 0 :::25 :::* LISTEN 4398/master
Configure Email Forwarding in Postfix
Let’s start with email forwarding configuration in Postfix configuration file (/etc/postfix/main.cf). Edit this file and add/edit the following configurations. Change example.com and example.net domain names with your domain name
virtual_alias_domains = example.com example.net virtual_alias_maps = hash:/etc/postfix/virtual
After making any changes in configuration files make sure to restart Postfix service.
Email Forwarding Examples
/etc/postfix/virtual is the file where we will add email forwarding rules. Let’s starts begin with the email forwarding rules.
@example.com [email protected] @example.net [email protected] [email protected]
Let’s verify all settings by sending emails to @example.com and @example.net domain email accounts.