Special Note: In this sample code, the sender's username and password are assigned to variables. Do NOT, I repeat, do NOT, leave plain text passwords in your code (unless you enjoy having your email hacked).
#!/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 passw +ord in your code! my $smtp = Net::SMTPS->new('outlook.com', Port => 587, doSSL => 'star +ttls', SSL_version=>'TLSv1'); $smtp->auth ( $username, $password ) or die "Could not authenticate wi +th 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=\"$boundar +y\"\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{ <body> <b>Email text (bold)</b> <br>Email text (normal) <p> <img src="cid:mypicture"> </body> }, ); $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;
"It's not how hard you work, it's how much you get done."
In reply to Re: Sending Email On Windows
by roho
in thread Sending Email On Windows
by bobinyec
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |