emailprocmail

How to store local copy of email before forwarding (in procmail)


This forwards emails to the address stored in the variable EMAIL_ADDR

:0 
* ^From
! $EMAIL_ADDR

I would like to save a local copy of the email before it's forwarded. Not sure of the syntax to do that. I know this doesn't do it:

:0 
* ^From
| tee $FILE
! $EMAIL_ADDR 

Solution

  • Try the script below (It is based on man procmailex).

    :0 
    * ^From
    {
       # use lock file to prevent simultaneous deliveries 
       :0 c:tee.lock
       | tee $FILE
    
       :0
       ! $EMAIL_ADDR
     }
    

    Instead of | tee $FILE you may use directly name of mailbox-file