#!/usr/bin/perl use strict; use warnings; use Net::SMTPS; use MIME::Base64 qw( encode_base64 ); my $from = 'Tester '; my $to = shift || 'tester@hotmail.com'; my $pic = shift || 'test.jpg'; # Email connection. my $username = 'tester@hotmail.com'; my $password = 'foo'; 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"; print "Sending mail\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: Perl Test Email\n"); $smtp->datasend("MIME-Version: 1.0\n"); $smtp->datasend("Content-type: multipart/mixed;\n\tboundary=\"$boundary\"\n"); $smtp->datasend("\n"); # Email body. $smtp->datasend("--$boundary\n"); $smtp->datasend("Content-type: text/plain\n"); $smtp->datasend("Content-Disposition: quoted-printable\n"); $smtp->datasend("Testing Perl email.\n"); # Email attachment. $smtp->datasend("--$boundary\n"); $smtp->datasend("Content-Type: image/jpeg; name=\"$pic\"\n"); $smtp->datasend("Content-Transfer-Encoding: base64\n"); $smtp->datasend("Content-Disposition: attachment; filename=\"$pic\"\n"); $smtp->datasend("\n"); open(my $fh2, '<', $pic) || die("Could not open Jpg file!"); binmode($fh2); local $/=undef; while (read($fh2, my $chunk, 72*57)) { my $buf = &encode_base64( $chunk ); $smtp->datasend($buf); } close($fh2); $smtp->datasend("\n"); $smtp->datasend("--$boundary--\n"); $smtp->dataend(); $smtp->quit; print "Mail sent\n"; exit;