<?xml version="1.0" encoding="windows-1252"?>
<node id="1014880" title="Sending Email Attachment Using Perl" created="2013-01-23 06:06:17" updated="2013-01-23 06:06:17">
<type id="115">
perlquestion</type>
<author id="1014878">
eliufoo</author>
<data>
<field name="doctext">
&lt;p&gt; Hi Monks,

I have the below server i got from Internet for sending email attachment. However, the attached files comes with 0Kb. &lt;/p&gt;

&lt;code&gt;
use MIME::Lite;
use Net::SMTP;

### Adjust sender, recipient and your SMTP mailhost
my $from_address = 'my@address.com';
my $to_address = 'my-email@remote.com';
my $mail_host = 'localhost';

### Adjust subject and body message
$subject = 'Weekly Mail';
my $message_body = "The information needed";

### Adjust the filenames
my $my_file_gif = '/usr/local/var/archive/';
my $your_file_gif = 'afro_samurai4.jpg';
my $my_file_zip = '/usr/local/var/archive/';
my $your_file_zip = 'CONFIGS_00_04-01-13.tar.gz';

### Create the multipart container
$msg = MIME::Lite-&gt;new (
  From =&gt; $from_address,
  To =&gt; $to_address,
  Subject =&gt; $subject,
  Type =&gt;'multipart/mixed'
) or die "Error creating multipart container: $!\n";

### Add the text message part
$msg-&gt;attach (
  Type =&gt; 'TEXT',
  Data =&gt; $message_body
) or die "Error adding the text message part: $!\n";

### Add the GIF file
$msg-&gt;attach (
   Type =&gt; 'image/jpg',
   Path =&gt; $my_file_gif,
   Filename =&gt; $your_file_gif,
   Disposition =&gt; 'attachment'
) or die "Error adding $my_file_gif: $!\n";

### Add the ZIP file
$msg-&gt;attach (
   Type =&gt; 'application/zip',
   Path =&gt; $my_file_zip,
   Filename =&gt; $your_file_zip,
   Disposition =&gt; 'attachment;filename=*'
) or die "Error adding $my_file_zip: $!\n";

### Send the Message
MIME::Lite-&gt;send('smtp', $mail_host, Timeout=&gt;60);
$msg-&gt;send; &lt;/code&gt;</field>
</data>
</node>
