Send emails with Perl

Perl is a general-purpose interpreted programming language, with powerful design features for text manipulation, nowadays it is mostly used for system administration and web development, its CPAN, wich stands for Comprehensive Perl Archive Network has more than 20,000 third party modules. Bellow, you can find a snippet I use to deliver emails with Perl using Gmail SMTP server.

#!/usr/bin/perl

use strict;
use warnings;
use Email::Send::SMTP::Gmail;

my ($mail,$error) = Email::Send::SMTP::Gmail->new(
    -layer => 'ssl',
    -port  => '465',
    -smtp  => 'smtp.gmail.com',
    -login => 'john.doe@gmail.com',
    -pass  => 'password'
);

die "session error: $error" if $mail ==-1;

$mail->send(
    -to          => 'jane.doe@gmail.com',
    -subject     => 'Greetings',
    -body        => 'Sent from PERL',
    -attachments => '/home/john/Documents/john.doe/test.txt'
);

$mail->bye