How to send message headers of new emails to another email address using Postfix?

Posted on 2006-04-10
Last Modified: 2011-09-20
I'm using Fedora Core 4 and Postfix as my mail server on a small domain I operate.

I would like to get the message headers from my mailbox sent to an email address of my choice... preferrably my cell phone.
I've been tinkering with aliases and .forward files to try and accomplish this, but haven't had much luck yet.

Has anyone here successfully done something like this?
Question by:scorbin
    LVL 19

    Expert Comment

    I have done some scripting using formmail

    and also some bash scripting...

    I think you can put a script in your local .forward in order to local deliver while also send a copy to your script.

    Author Comment

    I'm not entirely familiar with formmail, but am quite a bit more familiar with bash.  I'm not sure if this is the approach I want to take quite yet.  Of course, I'll result to brute force if need be, but my naiveity still thinks there may be a more innovative way to approach my problem.

    Have you got any other ideas?
    LVL 19

    Expert Comment

    there are some problems

    you need to write a parser to fully separate the headers. I think an approach could be to look for the first blank line and all previous lines are headers.
    if you can separate the headers to a temporary file,  it's a question only to mail such file to your defined email account.

    Author Comment

    The header shouldn't be too awefully bad to parse, I can always parse the source and retrieve the sender and subject.

    Maybe I should restate my main concerns.  I wasn't able to successfully figure a way to modify the aliases or .forward file to "mirror" messages to another email address.  I don't want to simply forward the messages, but instead detect when a new messsage arrives and then run a small script that parses the message and sends what I want from it.

    I can do the script, that's not really the problem.  It's finding a method to handle an event of a new mail message.

    Hopefully I haven't been overly ambiguous with my description.  If so let me know.
    LVL 19

    Accepted Solution

    I Understand better now

    well, if you are using sendmail, you can do this in the .forward file (The same I suppose you use to mirror messages) like in here:

    all this can be reduced to

    youruser, |/usr/local/scripts/
    where your script has the email as it's input.

    but I would consider procmail as the better tool for the job if you want to do things with each email received:

    Author Comment


    You're on top of it.  That's the page/info I was looking for.


    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    Cpanel and Mail logs 1 42
    Embeded Linux on Router 9 87
    Help with Ubuntu 14.04 LTS 10 112
    Iptables and mirroring ports 4 17
    I have seen several blogs and forum entries elsewhere state that because NTFS volumes do not support linux ownership or permissions, they cannot be used for anonymous ftp upload through the vsftpd program.   IT can be done and here's how to get i…
    Note: for this to work properly you need to use a Cross-Over network cable. 1. Connect both servers S1 and S2 on the second network slots respectively. Note that you can use the 1st slots but usually these would be occupied by the Service Provide…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now