Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MIME::Lite Question

Status
Not open for further replies.

andycruce

Programmer
Jun 25, 2002
11
0
0
US
I am trying to use MIME::Lite to send attachments to a message generated in perl. The code is below:


$msg = MIME::Lite->new(
From =>"$adminmail",
To =>"$rec[$em_ptr]",
Subject =>"$subject",
Type =>'multipart/mixed'
);

$msg->attach(Type =>'TEXT',
Data =>"$content"
);
if ($Attachments ne "") {

@AttachmentsList = split(/\|/,$Attachments);
for ($i=1; $i<=$#AttachmentsList; $i++) {
$msg->attach(Type =>'AUTO',
Path =>'/home/andy/public_html/BaseDir/Admin/',
Filename =>&quot;$AttachmentsList[$i]&quot;,
Disposition => 'attachment'
);
}
}

$msg->send;

I am downloading the attachment files and keeping their names in $Attachments with a format like |filename|filename|etc. When I have added all the attachments to the $Attachments variable I call this portion of code that pulls out the filenames in $Attachments and creates attchments for the e-mail message using MIME::Lite calls. Everything seems to go OK. It creates the email and when I receive it it has the proper attachments. When I use a .doc file name, the attachment even indicates a word document and when I use a .txt name it indicates a text file. However, when I try to open either of them from the e-mail they are blank even though the icon for the attached file in the e-mail shows a non-zero length. When I go and actually open the file I downloaded to the server and attached to the e-mail message it is fine. The file on the server has the information I downloaded from my pc. I've tried type of both text and auto on the attachment and that doesn't seem to do anything. Any suggestions of where I might go from here.

Thanks

Andy Cruce
 
Path is the path to the actual file, not the directory that it is contained in. Filename is the new name that you want to give the file when you send it.
So your code should read
Code:
$msg->attach(
     Type   =>'AUTO',
     Path   => &quot;/home/andy/public_html/BaseDir/Admin/$AttachmentsList[$i]&quot;,
     Filename => &quot;$AttachmentsList[$i]&quot;,
     Disposition => 'attachment'
);
Or just leave out the Filename parameter if you don't want to give the file a different name.

jaa
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top