Facebook X (Twitter) Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook X (Twitter) Instagram
    TecAdmin
    You are at:Home»Mail Services»How to Setup Mail Forwarding in Postfix

    How to Setup Mail Forwarding in Postfix

    By RahulApril 5, 20233 Mins Read

    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.

    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:

    1
    virtual_alias_maps = hash:/etc/postfix/virtual

    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:

    1
    source_email@example.com destination_email@example.org

    Where [email protected] is the email address that will have its incoming mail forwarded, and [email protected] is the email address where the mail will be forwarded.

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

      1
      2
      user1@example.com user1.forward@example.org
      user2@example.com user2.forward@example.org

    • Forward suppo[email protected] emails to [email protected] and [email protected]

      1
      support@example.com rahul@myemail.com admin@myemail.com

    • Forward any email sent to @example.com domain to [email protected]. Also forward any email sent to @example.net domain to [email protected] as well as [email protected]

      1
      2
      @example.com rahul@myemail.com
      @example.net rahul@myemail.com 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.

    Email mail Postfix
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    How to Validate Email Addresses in Python (Using Regular Expressions)

    Configuring Sendmail through the External SMTP relay

    Postfix: Sending Emails From External SMTP Servers

    Postfix: Sending Emails From External SMTP Servers

    View 3 Comments

    3 Comments

    1. Elio on July 12, 2019 11:41 pm

      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([email protected]) To destiny([email protected])
      forwaring another mail ([email protected])

      When arrive el mail to [email protected] through forwarding
      It does not show the mail of the sender [email protected]
      Show the sender’s mail using to do the relayhost example [email protected]

      Please helpe

      Reply
    2. amargujeti on June 13, 2019 10:06 am

      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

      Reply
    3. georgemr on February 3, 2017 5:19 pm

      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.

      Reply

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • Difference Between Full Virtualization vs Paravirtualization
    • Virtualization vs. Containerization: A Comparative Analysis
    • Using .env Files in Django
    • Using .env File in FastAPI
    • Setting Up Email Notifications for Django Error Reporting
    Facebook X (Twitter) Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.