Postfix mail forwarding
Postfix is a popular open-source mail transfer agent (MTA) that can be used to forward emails to other email addresses or domains. Here are some ways to set up postfix mail forwarding:
Method 1: Using the virtual_alias_maps
parameter
You can use the virtual_alias_maps
parameter in the postfix configuration file (/etc/postfix/main.cf
) to forward emails to other email addresses or domains.
For example, to forward all emails sent to [email protected]
to [email protected]
, you can add the following line to the main.cf
file:
virtual_alias_maps = hash:/etc/postfix/virtual
Then, create a file called /etc/postfix/virtual
with the following contents:
[email protected] [email protected]
This will forward all emails sent to [email protected]
to [email protected]
.
Method 2: Using the alias_maps
parameter
You can also use the alias_maps
parameter to forward emails to other email addresses or domains.
For example, to forward all emails sent to [email protected]
to [email protected]
, you can add the following line to the main.cf
file:
alias_maps = hash:/etc/postfix/aliases
Then, create a file called /etc/postfix/aliases
with the following contents:
[email protected]: [email protected]
This will forward all emails sent to [email protected]
to [email protected]
.
Method 3: Using a separate file for forwarding
You can also create a separate file for forwarding emails, such as /etc/postfix/forward
.
For example, to forward all emails sent to [email protected]
to [email protected]
, you can add the following line to the /etc/postfix/forward
file:
[email protected] [email protected]
Then, update the main.cf
file to include the following line:
forward_path = /etc/postfix/forward
This will forward all emails sent to [email protected]
to [email protected]
.
Method 4: Using a regex-based forwarding
You can also use a regex-based forwarding to forward emails to other email addresses or domains.
For example, to forward all emails sent to [email protected]
to [email protected]
, you can add the following line to the main.cf
file:
regex_maps = hash:/etc/postfix/regex
Then, create a file called /etc/postfix/regex
with the following contents:
/.*@[email protected]/ [email protected]
This will forward all emails sent to [email protected]
to [email protected]
.
Note: Make sure to restart the postfix service after making any changes to the configuration files.