I am configuring my Linux system to accept incoming emails and forward them to needed email accounts. For this setup, the Ubuntu operating system is used with the postfix mail server. We can configure Postfix as mail forwarding server using the virtual_alias_maps settings.
This tutorial will help you to set up a postfix server to forward the email to other email accounts.
Setup Mail Forwarding in Postfix
Forwarding emails to remote mailboxes via Postfix does not require local mailboxes. Any email received by the Postfix will be routed to remote mailboxes based on configuration.
Below example configuration will help you to configure example.com as mail forwarding domain on Postfix.
Edit Postfix main.cf in editor:
sudo vi /etc/postfix/main.cf
Add your mail forwarding domain to virtual_alias_domains and a configuration file with routing rules with virtual_alias_maps. You can add multiple virtual_alias_domains with space-separated.
virtual_alias_domains = example.com tecadmin.net virtual_alias_maps = hash:/etc/postfix/virtual
Next create and edit /etc/postfix/virtual file in editor:
sudo vi /etc/postfix/virtual
Now add the Postfix email forwarding rules as per your requirements. Below is some example:
- Forward [email protected] emails to [email protected]
[email protected] [email protected]
- Forwarding all the emails sent to any email id for domain example.com to [email protected]
@example.com [email protected]
- Forward incoming emails to [email protected] to the local Unix root account.
[email protected] root
Save and close the file. Next, create a hash file of the virtual and start postfix service.
postmap /etc/postfix/virtual
service postfix restart
Conclusion
In this tutorial, you have learned to configured Postfix to forward emails to other email accounts.