I receive emails from a sub-contractor. I need to automatically resend the content of these emails to a distribution list from my company email address. We currently use Outlook Exchange as our main mail server but I am willing (actually prefer) to use Linux to parse/redirect. I am not too concerned about scrubbing headers, just updating the FROM/SENDER and TO/RECIPIENT fields. There may also be attachments which need to be carried along.
I have seen a similar post here on SuperUser which references 'procmail' in one of the answers but is vague.
My best approach so far would be to set up a mail client on Linux to pull in the Outlook traffic then parse with procmail and resend. Has anyone seen examples of this? Have a better idea?
Thanks.
That's not how Procmail works. Procmail is an autonomous agent which typically runs on your mail server and processes each incoming message as it arrives.
The forwarding functionality you request isn't part of Procmail proper, but the Procmail distribution comes with a utility formail
which can rewrite headers for you.
Given a message on standard input, it can replace the "From:" and "To:" headers with new values like this:
formail -I"From: Important Account <corporation@example.com>" \
-I"To: Little Peon <person@example.org>" -ICc:
(The empty -ICc:
makes sure to zap any Cc:
header if there is one. You might also want to zap old Received:
headers.)
The output can then be piped to e.g. sendmail -oi -t
to submit it back into the mail stream.
Of course, this is also easy to put in a Procmail recipe if you want it to happen automatically when email arrives. This is really run of the mill Procmail processing so you should be able to find plenty of examples, including within the Procmail manual. But here's the long and the short of it;
:0c
* regex which matches the messages you want to forward
| formail -I"From: account@example.com" -I"To: person@example.org" -ICc: \
| $SENDMAIL $SENDMAILFLAGS -t
Remove the c
flag if you don't want to receive the original in your inbox. Remove the condition if you want to forward all mail unconditionally.