Limbic~Region has asked for the wisdom of the Perl Monks concerning the following question:

All,
I have a need to redirect a message to another address using Sendmail. Simple right - just create an alias. Well, I also need to drop the message ID. I figured I could still use an alias, but instead pipe it to a script with the only parameter being the new recipient address. I could then drop the message ID as I read in the message, change the recipient address, and resend the message. Uh oh, what about the original from address?

I started to write the script and quickly realized that there were too many conditions that may go wrong. So what I am looking for is a module that can do the following:

  • Read a message piped in from Sendmail
  • Modify the recipient address
  • Remove the message ID if present
  • Resend the message with the original from
  • Preferrably in memory (without writing a temporary file)

    I know there are a plethora of modules out there for SMTP, but I am not I am not sure if anyone of them can be bent to my will. Any suggestions?

    Thanks in advance - L~R

  • Replies are listed 'Best First'.
    Re: Modify and redirect SMTP mail help!
    by crenz (Priest) on May 02, 2003 at 17:53 UTC

      I'm a big fan of Mail::Audit, so my way to accomplish this would be something like (untested)

      use Mail::Audit; # read message from STDIN my $mail = Mail::Audit->new(); $mail->delete_header("Message-ID"); # set To: header if you want to # (not necessary for resend(), just for the look of it) $mail->replace_header("To", "Some Guy <someone@somewhere.com>"); $mail->resend("someone@somewhere.com");

      Note that your MTA might add a new Message-ID for you if you don't specify one. This is beyond Mail::Audit's control.

        crenz,
        Thanks - this looks exactly what I am looking for.

        Cheers - L~R

        Update: crenz mentioned this module to me in the CB, but I was confused - big surprise.

          I was the one that mentioned it :). In the meantime, I took a quick look at Mail::Audit's source. It doesn't seem to create a tempfile. However, if this is an important issue to you and you want to be really sure, make sure you review Mail::Internet and MIME::Entity as well, since Mail::Audit makes use of them.