Forward Postfix emails using /etc/aliases

Home > Search
  by

To forward an email from one address to another, you can use the /home/<username>/.forward file or /etc/aliases file.

 


/home/<username>/.forward

The forward file can be used to forward email from user1@example.com to user2@example.com. For example, to forward emails sent to webmaster to John Doe, you would first need to create a user account for webmaster. Then, create the .forward file for webmaster.

[root@server1 ~]# touch /home/webmaster/.forward

 

In the forward file, add a rule to forward emails from webmaster to John Doe.

webmaster: john.doe

 

The /var/log/maillog should show the email was forwarded from webmaster to John Doe.

Mar 28 20:5:17 mail postfix/local[4604]: 1426A5FFEC: to=<john.doe@example.com>, orig_to=<webmaster@example.com>,. . .

 

To forward emails to two or more recipients, separate the recipients with a comma.

webmaster: john.doe,jane.doe

 

Emails can also be forwarded to an external email address. For example, to forward emails from webmaster to john.doe@domain.com.

[root@server1 ~]# cat /home/natalie/.forward
webmaster: john.doe@domain.com

 

Instead of forwarding email to a user's email inbox, the email can be sent to a file, usually for logging purposes. For example, if there is a Web form that lets users email their feedback or surveys, these can be logged to a file.

[root@server1 ~]# cat /home/<username>/.forward
surveys: /var/log/surveys
feedback: /var/log/feedback

 


/etc/aliases

An advantage of forwarding emails using the /etc/aliases file instead of the /home/<username>/.forward files is that the /etc/aliases file is that you can have a single file to controlling the forwarding of emails. Also, if you want to forward emails from webmaster to John Doe, you do not need to create a user account for webmaster.

For example, to forward emails from webmaster@example.com to john.doe@example.com.

[root@server1 ~]# cat /etc/aliases
webmaster: john.doe

 

If you want to forward email to two or more recipients, separate each recipient with a comma.

[root@server1 ~]# cat /etc/aliases
webmaster: johne.doe,jane.doe

 

After editing the /etc/aliases file, the newaliases command must be run to update the aliases database.

[root@server1 ~]# newaliases

 

The /etc/aliases file probably starts with some comments and then two default entries:

  • postmaster: root
  • MAILER-DAEMON: postmaster

These default entries forward mail sent to the MAILER-DAEMON or postmaster to root.

[root@server1 ~]# cat /etc/aliases
#
# The following two aliases must be present to be RFC-compliant. 
# It is important to resolve them to 'a person' who reads mail routinely. 
# 
postmaster: root
MAILER-DAEMON: postmaster

 

Instead of forwarding email to a users email inbox, the email can be sent to a file, usually for logging purposes. For example, if there is a Web form that lets users email their feedback or surveys, these can be logged to a file.

[root@server1 ~]# cat /etc/aliases
surveys: /var/log/surveys
feedback: /var/log/feedback

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter in the box below so that we can be sure you are a human.




Comments