Inside Out

New mail notification with Procmail

Posted by: arun on: December 7, 2008

Problem: I have my local mail setup with mutt, fetchmail and procmail. And I would need a way to run an arbitrary script when new mail arrives and _not_ loose the mail from my inbox.

Solution: Procmail supports a nice feature called nesting. With nested blocks a procmail recipe can be assigned more than action.
e.g: Here’s a recipe to filter all my email from gmail:
:0:
* ^To:.*gmail\.com
{
:0 c
$MAILDIR

:0 h
| grep “From:” | ~/src/_scripts/ratpoison/newmail.sh
}

And the newmail.sh script
#!/bin/bash
read from
ratpoison -c "echo Mail $from"

Discussion: Here’s the breakup

  • *^To:*gmail.com Catch all mails which have their To: field containing gmail.com
  • Nesting: specify the actions inside { .. }
  • :0 c - Copy the mail into $MAILDIR
  • :0 h – Pipe the header into grep. And pipe the output (“From:*”) into newmail script
  • In newmail.sh script, read the piped content into variable $from and display that in ratpoison message bar

If your window manager has a notification tray, you may be interested in this. New to procmail, go here.

/me is having bit overdose of cookbooks these days ;)

1 Response to "New mail notification with Procmail"

[...] a comment » Few months ago, we discussed about a mail notification method for fetchmail/procmail and mutt combo. As you can see in that post, the script we wrote to [...]

Leave a Reply

Tweet tweet!

Visitor Stats

  • 444,852 Hitz

Disclaimer

All the opinions (text and images) expressed in this website are mine. They do not represent the opinion of any living/non-living individual/groups/institutions, I am associated with.

The comments belong to the ip-address they generate from.

Del.icio.us