Tugger the SLUGger!SLUG Mailing List Archives

[SLUG] Emailing Attachments from Perl


Hi All,
I have a perl script that emails attachments, but there seems to be a 
problem with it
When I receive the email its fine, but two others have received it, and 
the file is 0 bytes
My email client is Lotus Notes, while theirs is Outlook XP & Outlook 
Version 6.

I have also checked in mutt, and everything seems to be fine. Has anyone 
come up with this problem?

This is what the raw email looks like from the output of the linux 'mail' 
command:

>From edi@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx Thu Jun 26 08:06:43 2003
Envelope-to: roadtech@xxxxxxxxxxxxxxxxxxxx
Subject: Getronics Import Rejected
Content-Type: multipart/mixed; boundary="====1056578626===="
Mime-Version: 1.0
To: roadtech@xxxxxxxxxxxxxxxxxxxx
From: edi@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Date: Wed, 25 Jun 2003 23:03:46 +0100

  --====1056578626====
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

File Attached
--====1056578626====
Content-Type: application/octet-stream; name="100000.001"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="100000.001"
SjF8fEdFVFJPTjAxfDEzNTE1NiAwMXxTTEFNfHw2NjZ8MzQzfHwwMzA1MzB8MDk0MHx8fHx8fHx8
fFRSQU5TfHx8fHx8fHx8fHx8fHx8fHx8fHx8fApDMXx8fHx8fHxDTy1PUCAgICAgICAgICAgICAg
ICAgICAgICAgfCBNQUlOIFJPQUR8T05DSEFOIElNMyAxQU4gICAgICAgICAgICAgIHxJU0xFIE9G
IE1BTiAgICAgICAgICAgICAgICAgfHx8fHw3N3x8fHx8fHx8fDc0ODIzN3x8fHx8fHx8fHx8fHwg
ICAgICAgIHx8fApJMHxDUlNFU1Y4K3x8MXx8fHx8Cg==

--====1056578626====--

This is the perl script that emails the file:

 %mail = ( To       => $imp_failmail,
           From     =>'edi@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
           Subject  =>'Getronics Import Rejected',
           );

  $boundary = "====" . time() . "====";
  $mail{'content-type'} = "multipart/mixed; boundary=\"$boundary\"";
  $mail{smtp} = "$smtpserver";
  $message = encode_qp( "File Attached");
  $file = "$impdir/$impfile";
  print "$file\n";
  open (ATTACH,"<$file")  or die &err_check("Cannot Open file for emailing 
$impfile : $!\n");
  binmode ATTACH; undef $/;
  $mail{body} = encode_base64(<ATTACH>);
  close ATTACH;

  $boundary = '--'.$boundary;
  $mail{body} = <<END_OF_BODY;
  $boundary
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

$message
$boundary
Content-Type: application/octet-stream; name="$impfile"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="$impfile"
$mail{body}
$boundary--
END_OF_BODY
  sendmail(%mail) || print "Error: $Mail::Sendmail::error\n";
  }


Can anyone see anything wrong with this?

TIA

Scott