Procmail Tips: How to forward your email.

June 24, 2008 – 2:56 pm by Augie Schwer

Not that you would ever want to forward your email away from Sonic.net, but maybe you like the idea of archiving and searching your E-Mail at a secondary E-Mail location; to that end the post below details how you should be forwarding your E-Mail in any UNIX environment.

You know that looping your mail is a bad idea; that is forwarding your email to Gmail and then forwarding that back to yourself, ad infinitum, you get the idea. It’s equally a bad idea to forward DSNs or bounce messages to Gmail (or anywhere really); as it causes the same sort of loop and the same kind of aggravation for your System Administrator. The following is a procmail recipe that works for me; just drop this into your .procmailrc in your home directory.

SENDMAIL=/usr/sbin/sendmail
FORMAIL=/usr/bin/formail

:0
* ^X-Loop: Your_Email_Address@sonic.net
/dev/null

:0E
* ^TO_Your_Email_Address\+0×96rds@sonic\.net
$DEFAULT

:0cE
| $FORMAIL -A “X-Loop: Your_Email_Address@sonic.net” | $SENDMAIL -f Your_Email_Address+0×96rds@sonic.net -oi Your_Email_Address@gmail.com

In detail:

SENDMAIL=/usr/sbin/sendmail
FORMAIL=/usr/bin/formail

Sets up some variables.

:0
* ^X-Loop: Your_Email_Address@sonic.net
/dev/null

Discards the message if it has the “X-Loop” header in it; this stops circular mail loops; for example if you forwarded Your_Email_Address@sonic.net to Your_Email_Address@gmail.com and then forwarded that back to Your_Email_Address@sonic.net.

:0E
* ^TO_Your_Email_Address\+0×96rds@sonic\.net
$DEFAULT

Places the message in your Inbox and does not forward it on if the “To” header contains our address plus the special string. This stops you from forwarding those nasty bounce messages to the server that just sent you the bounce, thus causing a ping pong affect.

Little known fact: your_user_name+anything@sonic.net will go to your_user_name@sonic.net, so you can utilize that little “+anything” to do special filtering like in this script.

:0cE
| $FORMAIL -A “X-Loop: Your_Email_Address@sonic.net” | $SENDMAIL -f Your_Email_Address+0×96rds@sonic.net -oi Your_Email_Address@gmail.com

Finally this bit adds the above conditions to your message before forwarding it on to your “other” E-Mail provider.

Share and Enjoy:
  • Digg
  • del.icio.us
  • Pownce
  • Slashdot
  • StumbleUpon
  • Technorati
  • TwitThis

  1. One Response to “Procmail Tips: How to forward your email.”

  2. Thanks a lot! This saved me so much trouble. I have quite a complex set of procmail rules, and since I added gmail forwarding I’ve been producing a loop or two. This fixed everything :)

    By Ramon on Apr 18, 2009

Post a Comment

Please Note: Blog comments are not intended as a direct support contact. If you are having a technical problem, or something equally time-sensitive, please contact Sonic.net Support by sending an email to support@sonic.net or calling 707-547-3400 (phones open 6am-11pm M-F, 8am-10pm weekends).