I would like to use procmail to forward a message to another email address. Both the headers and body of the incoming message should be in the body of the outgoing message (inline forwarding).
Example incoming message:
From: [email protected]
To: [email protected]
Subject: Test
Date: Mon, 03 Nov 2014 05:00:04 GMT
This is a test
The forwarded message should be like this:
From: [email protected]
To: [email protected]
Subject: Fwd: Test
Date: Mon, 03 Nov 2014 05:01:00 GMT
From: [email protected]
To: [email protected]
Subject: Test
Date: Mon, 03 Nov 2014 05:00:04 GMT
This is a test
Can this be done using procmail, maybe in conjunction with something like formail?
Easy enough.
:0
* Some conditions, perhaps? Omit this line to forward unconditionally
* ^Subject:[ ]*\/.*
| (echo From: [email protected]; echo To: [email protected]; \
echo "Subject: Fwd: $MATCH"; echo; cat -) | $SENDMAIL -t
If you don't care about forwarding the original Subject header verbatim, this can be simplified additionally.
The -t
flag to sendmail
says to use whatever To:
and Cc:
headers are in the message to determine the recipient. I omitted generating a Date:
because (most imitations of) Sendmail will do that for you.
The stuff in the square brackets should be one space and one tab, as usual.
If you want to keep a copy, either add Bcc: yourself
(and take care to not have the incoming copy trigger a mail loop!) or change :0
to :0c
which makes Procmail continue down the rest if the recipe file.