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/vnd.ms-excel’,
Path => “c:/path/to/some/spreadsheet/filename.xls”,
Filename => ‘filename.xls’,
Disposition => ‘attachment’
) or die “Error attaching test file: $!”;

#SEND THE MESSAGE.
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? $!/$?”;

__END__

Advertisements

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

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: