Wednesday, February 15, 2006

Dot forward

Individual UNIX users can use mail aliasing by means of the .forward file.
When delivering email to a user, sendmail checks to see if the user has a .forward file in his home directory. If the file is present, the contents are read and treated as an alias for that person's email. So, for example, if I created a .forward file with the line jsmith@host2.uiuc.edu, all my email would be forwarded to that address instead of delivered to my mailbox.

The .forward file can have anything in it that the right-hand side of an alias can. You can specify another user, a filename, or a program to pipe it to. You can also seperate multiple entries with a comma or a newline. However, since alias expansion is done recursively until there's nothing left to expand, you have to do something different if you're sending a copy of the mail to yourself. For example, say user jsmith wants to send a copy of all her mail to user johndoe, but still keep a copy for herself. You'd think to use this .forward file:

jsmith
johndoe

The problem is that when sendmail goes to deliver a copy of the mail to jsmith, the .forward file will be expanded again, resulting in a mail loop! To avoid this, sendmail allows you to put a \ character before an entry in a .forward file which tells it not to expand that entry if it's an alias. So, the above file would be:
\jsmith
johndoe

Reference: Sendmail tutorial
Post a Comment