I'd move
close MSG;
outside of the for loop just for aesthetic purposes and check for errors on your open statement:
open (MSG, ">>mailmessage") or die "File open failed: $!\n";
but otherwise it performs as I would expect. Try saving a copy of your mail message to a file and invoke the program like so:
/tmp/mailparser.pl < mail.message.file
This suggests that you'll probably have to modify your procmail config line in some way, but I'm not familiar with procmail.
Update: I've had a similar problem using the /etc/aliases file to strip/redirect mail to a special account. I solved my problem by parsing the message and then resending it to a different account. This is sort of ugly, but it works until I can figure out the correct method:
#/etc/aliases entry
## The below entry saves an unaltered copy on account original, and
## pipes the incoming message through our program which
## resends to the final destination account. Be sure to execute
## 'newaliases' after you modify the /etc/aliases for the changed
## entry to be updated.
original: \original, "|/tmp/mailparser.pl"
The modified perl program:
##
# MboxParser stuff here
##
use MIME::Lite;
my $msg = new MIME::Lite
To => 'targetaccount@same.site.net',
From => $from,
Cc => $cc,
Subject => $subject,
Type => 'TEXT',
Comments => $to, ## save original to: if needed
Data => $body_str;
MIME::Lite->send('smtp', "some.smtp.net", Timeout=>60);
$msg->send;
--Jim
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.