2

I have setup a Postfix mail server, and my goal was to pipe incoming emails to a script. I did this via Procmail. The script is getting run without any issues.

my issue is: I want to deliver a copy of the incoming email to the users inbox as well. following is my .procmailrc file. Also I'm using Maildir format.

LOGFILE=$HOME/procmail.log
VERBOSE=YES
SHELL=/bin/sh
MAILDIR=$HOME/Maildir
:0
|/home/user1/script.sh

:0c
!user1@notification.mydomain.com

with the above .procmailrc file, script is getting run, but no email is getting delivered to users inbox.

Zareh Kasparian
  • 753
  • 5
  • 20
  • https://serverfault.com/questions/1053004/can-procmail-be-configured-to-get-rid-of-mail-after-it-is-passed-to-a-script is the opposite problem, which is more common. – tripleee Jun 13 '22 at 04:14

2 Answers2

4

You need a c flag on the first recipe (and no c flag on the second, unless you want a third copy of the message after this delivery).

In very brief, the first successful delivering recipe terminates Procmail's processing of this message. If you want it to continue after that point, add a c ("clone") flag (but in more complex scenarios perhaps also some sort of error checking and fallback processing, via the e and/or E flags).

tripleee
  • 1,416
  • 3
  • 15
  • 24
0

Thanks to @trpleee it worked for me. following is the final .procmailrc file.

PATH=/usr/local/bin:/bin:/usr/bin
LOGFILE=$HOME/procmail.log
VERBOSE=YES
SHELL=/bin/sh
DEFAULT=$HOME/Maildir/
:0c
|/home/user1/script.sh
Zareh Kasparian
  • 753
  • 5
  • 20
  • 1
    The final `$Maildir` is a syntax error. If you want to deliver to a folder by this name unconditionally, add a `:0` on the previous line to mark this as a recipe. (But if this is your complete `.procmailrc`, there is no variable named `$Maildir` either.) – tripleee Jun 14 '22 at 18:11
  • @tripleee yes you are correct, it was a mistype. i have corrected. no need for the $Maildir. since DEAFULT is covering it. – Zareh Kasparian Jun 15 '22 at 06:03