Users can redirect their own mail by placing a .forward file in their home directory. The .forward file is a plaintext file with a comma-separated list of mail addresses. Any mail sent to the user is then forwarded to these addresses. If the .forward file contains a single address, all email for that user is redirected to that single email address. For example, suppose that the following .forward file is placed in the home directory of a user named emily:
All email addressed to emily is automatically sent to the user name ashley on the same system. User emily does not receive mail at all.
You can also forward to a user name on another system by listing the complete email address. For example, I have added a .forward file with the following line to send my messages (addressed to my user name, naba) to the mail address [email protected]:
Now, suppose I want to keep a copy of the message on this system, in addition to forwarding to the address [email protected]. I can do so by adding the following line to the .forward file:
[email protected], naba\
I simply append my user name and end the line with a backslash. The backslash (\) at the end of the line stops sendmail from repeatedly forwarding the message (because when a copy is sent to my user name on the system, sendmail processes my .forward file again — the backslash tells sendmail not to forward the message repeatedly).
Another use of the .forward file is to run procmail to handle some mail messages automatically. For example, suppose that you want to delete any email message that comes from an address containing the string mailing_list. Here's what you do to achieve that:
1. Create a .forward file in your home directory, and place the following line in it:
This line causes sendmail to run the external program /usr/bin/procmail and to send the email messages to the input stream of that program. You can run any external program this way, by invoking it in the .forward file.
2. Create a text file named .procmailrc in your home directory, and place the following lines in that file:
# Delete mail from an address that contains mailing_list :0
* AFroiri:.*iriailing_list /dev/null
3. Log in as root and set up a symbolic link in /etc/smrsh to the /usr/bin/procmail program with the following command:
ln -s /usr/bin/procmail /etc/smrsh/procmail
This step is necessary because sendmail uses the SendMail Restricted Shell — smrsh —to run external programs. Instead of running /usr/bin/procmail, smrsh runs /etc/smrsh/procmail. That's why you need the symbolic link. This is a security feature of sendmail that controls what external programs it can run.
That's it! Now if you receive any messages from an address containing mailing_list, the message will be deleted.
By the way, if you want only to run procmail, then you can skip the part about adding it to .forward; simply create a .procmailrc file in your home directory, and sendmail will automatically invoke procmail to process your mail using the rules you specify in the .procmailrc file.
insider With procmail, you can perform other chores, such as automatically storing messages insight in a file or forwarding messages to others. All you have to do is create an appropriate .procmailrc file in your home directory. To learn more about procmail, type man procmail; to see examples of .procmailrc, type man procmailex.
Was this article helpful?
This Report Will Show You How To Make Money By Providing Writing Services To Other Internet Marketers. Learn how to make money by writing the right way. Grab your copy of this report now and learn. Why writing is a great way to earn money. How to compete with cheap writers, even if you charge a lot more money.