How to send email with attachment in PERL

Here is a sample code which demonstrates how to send an email with file attachement.


#!/usr/bin/perl

my $FileName = "/var/home/myfile.jpg";
my $FileNameToMail = "ImageFile.jpg";

SendRecFile();

sub SendRecFile {

use MIME::Lite;

my $msg = MIME::Lite->new(
From => "email\@email.com",
To => "you\@domain.com",
Subject => "Testing Attachment in PERL",
Type => "multipart/mixed",
);

$msg->attach(
Type => 'TEXT',
Data => "File is attached",
);

$msg->attach(
Type => 'image/jpeg', # Content Type
Path => $FileName
Filename => $FileNameToMail,
Disposition => 'attachment'
);

$msg->send;
}

RSS feed for comments on this post. TrackBack URI

Leave a Reply