in reply to Re: Re: accessing mailbox files
in thread accessing mailbox files

If all you are trying to do is to take some raw email messages in files and forward them to another account, then look at using formail. It is installed along side sendmail, and is useful for parsing email messages.

I have used the following to send an entire mbox file to another user:

cat <mboxfile> | formail +1 -ds sendmail -oem <dest-address>

I admit that I have not read your other questions, so I may be off base with what you are trying to achieve, but I always think it wise to look at the tools you have available with your mail system before starting to write your own...

- Cees

Replies are listed 'Best First'.
Re: Re: Re: Re: accessing mailbox files
by jc23 (Acolyte) on Jul 29, 2003 at 16:03 UTC
    Cees,

    Sending raw email messages to another mbox is exactly what I want to do. However, I want each message in the original mbox to be a separate email in the destination mboxl and not one big file.Will formail allow this?

    thanks

    jc

      Yes it will allow this. With the command I gave you above, formail will parse the mbox file, split out the separate email messages, and pipe each message to sendmail. Sendmail gets the parameters -oem <dest-address> which will send the mails to that email address. So if you had 5 messages in your mbox file, sendmail will send 5 separate messages.

      Here is what the switches do:

      • +1 skip the first message in the file (usually a POP3 header)
      • -d the file does not have to be in strict mbox format
      • -s execute the following command for each message. in this case execute 'sendmail -oem <dest-address>'

      A quick search on google found many man pages on formail. They might give some more insight into what it can do. The best way to learn is just to try it out and see.

      By the way, I initially said that formail came with sendmail. That was incorrect. It comes as part of the procmail package.

      - Cees

        Hey Cees, Excellent command. I ran the

        cat msg | formail +1 -ds /usr/lib/sendmail  -oem <dest addy> and it works great when msg is one big mbox file with multiple messages inside. I was wondering can I run that command if msg contains just one email file? I want to do something like  cat msg | /usr/lib/sendmail -m <dest> in a loop for a directory of files, but that command doesnt work at all.

        thanks

        jc