#!/usr/bin/perl use strict; use warnings; use Net::SMTPS; use MIME::Lite; use MIME::Base64 qw( encode_base64 ); my $to = 'email@example.com'; my $from = 'email@hotmail.com'; my $subject = 'Sample Subject'; my $file = 'C:\temp\sample.jpg'; my $username = 'MyEmail@hotmail.com'; my $password = 'MyPassword'; # Warning: Do NOT leave plain text password in your code! my $smtp = Net::SMTPS->new('outlook.com', Port => 587, doSSL => 'starttls', SSL_version=>'TLSv1'); $smtp->auth ( $username, $password ) or die "Could not authenticate with Outlook.\n"; ###################################################################### # Email - header. ###################################################################### my $boundary = 'frontier'; $smtp->mail($from); $smtp->recipient($to, { SkipBad => 1 }); $smtp->data(); $smtp->datasend("To: $to\n"); $smtp->datasend("From: $from\n"); $smtp->datasend("Subject: $subject\n"); $smtp->datasend("MIME-Version: 1.0\n"); $smtp->datasend("Content-type: multipart/mixed;\n\tboundary=\"$boundary\"\n"); $smtp->datasend("\n"); ###################################################################### # Email - text plus image embedded in email body. ###################################################################### $smtp->datasend("--$boundary\n"); my $msg = MIME::Lite->new( Type =>'multipart/related' ); $msg->attach( Type => 'text/html', Data => qq{
Email text (bold)
},
);
$msg->attach(
Type => 'image/jpeg',
Id => 'mypicture',
Path => $file,
);
$smtp->datasend( $msg->as_string );
######################################################################
# Email - finish.
######################################################################
$smtp->datasend("\n");
$smtp->datasend("--$boundary--\n");
$smtp->dataend();
$smtp->quit;
exit;