Procmail

From Indie IT Wiki
Revision as of 14:54, 22 March 2016 by imported>Indieit
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Procmail, a mail delivery agent (MDA) able to sort incoming mail into various directories and filter out spam messages. While Procmail is available for installation and is stable it is no longer developed or maintained.

System Wide Settings

/etc/procmailrc

# Use maildir-style mailbox in user's home directory
DEFAULT=$HOME/.maildir/
# Log actions to file
LOGFILE=/var/log/procmail.log
# Log synopsis of messages
LOGABSTRACT=all
# Be verbose
VERBOSE=no

Introduction

All these RECIPES are based on your personal procmail file located in...

~/.procmailrc

Documentation

How to forward a message but still leave a copy on the server

:0c                     # That's colon, zero, lowercase cee
! self@other-place.net  # That's exclamation mark, address to forward to

How to send just the body of a message to a program

:0 bc:   # archive things sent to junk mailing list
* ^To:.*junk
| gzip >> junk-archive.gz

Here we're using two flags. The b flag means that the action line will just take the body of the message, and not the header. The c line, again, means to just take a copy of the message for this recipe, and pass it along to the recipes after. We're using that because we want to archive the message, but we'd also like it to be filed in our mail inbox as usual.

How to match the sender and / or subject of a message

:0
* ^From.*bob
* ^Subject:.*(joke|funny)

How to send a copy of a message which matches a subject

:0c
* ^Subject:.*appears to be wedged$
! me@mydomain.com

Auto Reply For Server

:0 h c
* ^From(.*james.*|.*steve.*)
* ^Subject:.*status$
* !^FROM_DAEMON
* !^X-Loop: root@server.com
| (formail -r -I"Precedence: junk" \
   -A"X-Loop: root@server.com" ; \
   echo `/usr/bin/uptime`) | $SENDMAIL -t

Capture Correct Email Address Then Forward Rest To Spam

# basic settings
SHELL=/bin/bash
MAILDIR=${HOME}/.maildir
#VERBOSE=yes
#LOGABSTRACT=no
#LOGFILE=${HOME}/procmail.log

# capture correct email addresses
:0:
* ^TO_[0-9][0-9][0-9][0-9]@(this|that)domain[.]co[.]uk|\
  ^TO_orders@(this|that)domain[.]co[.]uk|\
  ^TO_orders@anotherdomain[.]co[.]uk
${DEFAULT}

# forward all the rest to spam@
:0
! spam@domain.co.uk