Postfix is a popular open-source mail transfer agent (MTA) used on Linux systems to route and deliver email. One of the many features it offers is email forwarding, which allows you to forward incoming emails to another email address automatically. This article will guide you through the process of configuring email forwarding in Postfix.

Advertisement

Installing Postfix

Before configuring email forwarding, ensure that Postfix is installed on your system. If it’s not, you can install it using the package manager for your Linux distribution.

  • For Debian/Ubuntu:
    sudo apt-get update 
    sudo apt-get install postfix 
    
  • For CentOS/RHEL:
    sudo yum install postfix 
    

Configuring Email Forwarding in Postfix

Postfix allows you to configure email forwarding using the virtual alias maps. These maps define the email forwarding rules for the system. To configure email forwarding in Postfix, follow these steps:

Step 1: Edit the Postfix configuration file

Open the main Postfix configuration file /etc/postfix/main.cf in a text editor:

sudo nano /etc/postfix/main.cf 

Locate the virtual_alias_maps directive in the configuration file. If it’s not present, add the following line to the end of the file:

This configuration line tells Postfix to use the /etc/postfix/virtual file as the source of virtual alias maps.

Step 2: Create and edit the virtual alias map file

Create the virtual alias map file /etc/postfix/virtual if it doesn’t exist:

sudo touch /etc/postfix/virtual  

Open the virtual alias map file in a text editor:

sudo nano /etc/postfix/virtual 

Step 3: Add email forwarding rules

Add the email forwarding rules to the virtual alias map file using the following syntax:

Where source_email@example.com is the email address that will have its incoming mail forwarded, and destination_email@example.org is the email address where the mail will be forwarded.

  • You can add multiple email forwarding rules, one per line:

  • Forward support@example.com emails to rahul@myemail.com and admin@myemail.com

  • 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

Step 4: Update the virtual alias map database

After adding the email forwarding rules, save the file and exit the text editor. Next, update the virtual alias map database using the following command:

sudo postmap /etc/postfix/virtual 

This command generates a database file named /etc/postfix/virtual.db that Postfix uses to look up the email forwarding rules.

Step 5: Reload Postfix

Finally, reload the Postfix configuration to apply the changes:

sudo systemctl reload postfix 

Testing Email Forwarding

To test the email forwarding configuration, send a test email to the source email address you configured for forwarding. If everything is configured correctly, the email should be forwarded to the destination email address automatically.

Conclusion

Configuring email forwarding in Postfix is a simple yet powerful feature that can help you manage your email more efficiently. By following the steps outlined in this article, you can easily set up email forwarding in Postfix and route incoming messages to the desired destination. This capability is especially useful when consolidating multiple email accounts or redirecting messages to a different email address.

Share.

3 Comments

  1. Thanks this works well

    BUT…

    When make forwarder to another email via gmail relayhost, it does not show the name of the email from the original sender, it shows the name of my host configured in google
    example:
    relayhost = [smtp.gmail.com]:587

    From mail sender(correo@hotmail.com) To destiny(admin@mydomain.com)
    forwaring another mail (anothermail@outlook.com)

    When arrive el mail to anothermail@outlook.com through forwarding
    It does not show the mail of the sender correo@hotmail.com
    Show the sender’s mail using to do the relayhost example correoforrelayhost@gmail.com

    Please helpe

  2. hi rahul

    i have stuck in postfix

    i have an private client ( 10.0.21.16 ) and Non -DMZ server ( 10.92.101.4) and DMZ server ( 10.92.103.1)

    first i relayed my 10.0.21.16 mails to NON- DMZ

    from Non -DMZ i have routed to DMZ

    Now from DMZ i want to send (relay or route) to public domains ?

    Note : i have bought public domain for DMZ server , my both client and Non – DMZ server have local domain which is using by inserting local domain in /etc/hosts

  3. In order for this to work, after the creation of file /etc/postfix/virtual with the forwarding rules and before reloading the postfix service with postix reload, the following should be executed: postmap /etc/postfix/virtual.

Leave A Reply

Exit mobile version