use warnings; use strict; use Carp; use MIME::Lite; use Net::SMTP::SSL; sub send_mail { # Function parameters - replaced by absolute values my $to = 'someone@gmail.com'; my $subject = "Test"; my $from = 'someoneelse@gmail.com'; my $password = "someoneelsepassword"; ## Beautification code my $from_mime = $from; my $count = @_; if( $count ) { my $from_name = shift; $from_mime = "\"$from_name\" <$from>"; } ## End of Beautification code my $msg = MIME::Lite->new ( From => "$from_mime" , To => "$to" , Subject => "$subject" , ); $msg->attach( Type => 'text/html', Data => qq{
Here's my image:
},
);
$msg->attach(
Type => 'image/png',
Id => 'cpan.png',
Path => 'cpan_banner.png',
);
my $smtp;
if (not $smtp = Net::SMTP::SSL->new('smtp.gmail.com',
Port => 465,
Debug => 1)) {
croak "Could not connect to server\n";
}
$smtp->auth( $from, $password )
|| croak "Authentication failed!\n";
$smtp->mail($from . "\n");
my @recepients = split(/,/, $to);
foreach my $recp (@recepients) {
$smtp->to($recp . "\n");
}
$smtp->data();
$smtp->datasend( $msg->as_string() );
$smtp->dataend();
$smtp->quit;
}
send_mail();