Sending Emails with Attachments programatically

I Found this cool way 2 send attachments (multipart messages) via Perl:

use MIME::Lite;

@mailtos = (’emailaddr_1′, ’emailaddr_2′, … ’emailaddr_n’);

my $mime_msg = MIME::Lite->new( #SET UP A MULTIPART MESSAGE OBJECT.
From => ’emailaddr_0′,
To => join(‘, ‘, @mailtos),
Subject => ‘Subject Text’,
Type => ‘multipart/mixed’
) or die “Error attaching message: $!/$?”;

$mime_msg->attach( #SET UP THE MESSAGE TEXT.
Type => ‘TEXT’,
Data => ‘Message Body Text’
) or die “Error attaching spreadsheet: $!/$?”;

$mime_msg->attach( #SET UP THE (1st) SPREADSHEET ATTACHMENT.
Type => ‘application/’,
Path => “c:/path/to/some/spreadsheet/filename.xls”,
Filename => ‘filename.xls’,
Disposition => ‘attachment’
) or die “Error attaching test file: $!”;

MIME::Lite->send(‘smtp’, ‘mail.afc.local’, Timeout => 60); #Winblows / ActivePerl.
#MIME::Lite->send(‘sendmail’, ‘/usr/local/bin/sendmail’, Timeout => 60) #Linux / Unix.
$mime_msg->send() or die “Could not send? $!/$?”;



Feel Free to Comment (Name/Email/Website optional):

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: