Search code examples
emailprocmail

Using procmail to copy emails to another address and altering "from"


I get email alerts that are generated by a user on one of my servers. These alerts are generated by server@######.com and they have to do with third party software not working properly.

I'm trying to use procmail to copy (as I want to keep receiving these) these emails to [email protected].

I'm looking for emails that, in their body, have "C:" followed by 6 characters, a dot, and 3 more characters. All of that is working fine, but I want the third party to get these emails from me [email protected] rather than server.

How can I copy the email to a third party AND change the from address to be [email protected]?

Here's the procmail file:

cat .procmailrc
DROPPRIVS=yes
LOGFILE=$HOME/procmail.log

:0 c:
* B ?? C:......\....
! [email protected]

:0 B:
* ^To: .*[email protected]
! [email protected]

Solution

  • Inject the headers you want with formail before piping to sendmail. (Recall that ! is basically a shorthand for | $SENDMAIL $SENDMAILFLAGS.)

    Do I understand correctly that the first recipe is the one you would like to modify?

    :0 c  # No lockfile when forwarding
    * B ?? C:......\....
    | formail -I 'From: [email protected]' \
      | $SENDMAIL $SENDMAILFLAGS [email protected]
    

    Your second recipe similarly should not have a lock file; see http://www.iki.fi/era/procmail/mini-faq.html#locking