How to Setup Mail Forwarding in Postfix

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.
1 – Forward all emails sent to info@example.com and info@example.net to rahul@myemail.com.
info@example.com rahul@myemail.com info@example.net rahul@myemail.com 
2 – Forward support@example.com emails to rahul@myemail.com and admin@myemail.com
support@example.com rahul@myemail.com admin@myemail.com 
3 – Forward any email sent to @example.com domain to rahul@myemail.com. Also forward any email sent to @example.net domain to rahul@myemail.com as well as admin@myemail.com
@example.com rahul@myemail.com @example.net rahul@myemail.com admin@myemail.com 

Verify Setup

Let’s verify all settings by sending emails to @example.com and @example.net domain email accounts.

Thanks for Visit Here

Comments