NAME
Email::Send::SMTP::Gmail - Sends emails with attachments supporting Auth over TLS or SSL (for example: Google's SMTP and AWS SES).
SYNOPSIS
use strict;
use warnings;
use Email::Send::SMTP::Gmail;
my ($mail,$error)=Email::Send::SMTP::Gmail->new( -smtp=>'smtp.gmail.com',
-login=>'whateveraddress@gmail.com',
-pass=>'whatever_pass');
print "session error: $error" unless ($mail!=-1);
$mail->send(-to=>'target@xxx.com', -subject=>'Hello!', -body=>'Just testing it',
-attachments=>'full_path_to_file');
$mail->bye;
DESCRIPTION
Simple module to send emails through Google's SMTP with or without attachments. Also supports regular Servers (with plain or none auth). Works with regular Gmail accounts as with Google Apps (your own domains). It supports basic functions such as CC, BCC, ReplyTo.
- new(-login=>'', -pass=>'' [,-smtp=>'',layer=>'',-port=>'',-debug=>''])
-
It creates the object and opens a session with the SMTP.
- smtp: defines SMTP server. Default value: smtp.gmail.com
- layer: defines the secure layer to use. It could be 'tls', 'ssl' or 'none'. Default value: tls
- port: defines the port to use. Default values are 25 for tls and 465 for ssl
- timeout: defined Timeout for the connection. Default is 60 secs
- auth: defines the authentication method. Using AUTO (default value) the system uses the list provided by the server. This module supports: ANONYMOUS, CRAM-MD5, DIGEST-MD5, EXTERNAL, GSSAPI, LOGIN and PLAIN (it's currently based on SASL::Perl module).
- debug: see the log information
-
Also supports SSL parameters as:
- ssl_verify_mode: SSL_VERIFY_NONE | SSL_VERIFY_PEER
- ssl_version: SSLv23 | ''
- ssl_verify_path: SSL_ca_path if SSL_VERIFY_PEER
- ssl_verify_file: SSL_ca_file if SSL_VERIFY_PEER
- send(-from=>'', -to=>'', [-subject=>'', -cc=>'', -bcc=>'', -replyto=>'', -charset=>'', -body=>'', -attachments=>'', disposition=>'', -sns_topic=>'', -verbose=>'1'])
-
It composes and sends the email in one shot
- to, cc, bcc: comma separated email addresses
- contenttype: Content-Type for the body message. Examples are: text/plain (default), text/html, etc.
- sns_topic: AWS SES header X-SES-CONFIGURATION-SET to manage email queue in Amazon Web Services.
- disposition: Set "inline" in sending embeeded attachments. For example using <body><img src="cid:logo.png"><br>Test with Image</body>
- attachments: comma separated files with full path
- attachmentslist: hashref $list, in format $list->[x]->{name} of files with full path. Example: $list->[0]->{file}='/full_path/file.pdf'
- bye
-
Closes the SMTP session
-
Returns SMTP banner
Examples
Examples
Send email composed in HTML using Gmail
use strict;
use warnings;
use Email::Send::SMTP::Gmail;
my ($mail,$error)=Email::Send::SMTP::Gmail->new( -smtp=>'smtp.gmail.com',
-login=>'whateveraddress@gmail.com',
-pass=>'whatever_pass');
print "session error: $error" unless ($email!=-1);
$mail->send(-to=>'target@xxx.com', -subject=>'Hello!',
-body=>'Just testing it<br>Bye!',-contenttype=>'text/html');
$mail->bye;
Send email using a SMTP server without secure layer and authentication
use strict;
use warnings;
use Email::Send::SMTP::Gmail;
my $mail=Email::Send::SMTP::Gmail->new( -smtp=>'my.smtp.server',-layer=>'none', -auth=>'none');
$mail->send(-from=>'sender@yyy.com', -to=>'target@xxx.com', -subject=>'Hello!',
-body=>'Quick email');
$mail->bye;
Send email with attachments in comma separated format
use strict;
use warnings;
use Email::Send::SMTP::Gmail;
my $mail=Email::Send::SMTP::Gmail->new( -smtp=>'smtp.gmail.com',
-login=>'whateveraddress@gmail.com',
-pass=>'whatever_pass');
$mail->send(-to=>'target@xxx.com', -subject=>'Hello!',
-body=>'Just testing it<br>Bye!',-contenttype=>'text/html',
-attachments=>'/full_path/file1.pdf,/full_path/file2.pdf');
$mail->bye;
Send email with attachments using hashref
use strict;
use warnings;
use Email::Send::SMTP::Gmail;
my $mail=Email::Send::SMTP::Gmail->new( -smtp=>'smtp.gmail.com',
-login=>'whateveraddress@gmail.com',
-pass=>'whatever_pass');
my $att;
$att->[0]->{file}='/full_path/file.pdf';
$att->[1]->{file}='/full_path/file1.pdf';
$mail->send(-to=>'target@xxx.com', -subject=>'Hello!',
-body=>'Just testing it<br>Bye!',-contenttype=>'text/html',
-attachmentlist=>$att);
$mail->bye;
BUGS
Please report any bugs or feature requests to bug-email-send-smtp-gmail at rt.cpan.org
or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Email-Send-SMTP-Gmail. You will automatically be notified of the progress on your bug as we make the changes.
SUPPORT
You can find documentation for this module with the perldoc command.
perldoc Email::Send::SMTP::Gmail
You can also look for information at:
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Email-Send-SMTP-Gmail
AnnoCPAN: Annotated CPAN documentation
CPAN Ratings
Search CPAN
Repository
AUTHORS
Juan Jose 'Peco' San Martin, <peco at cpan.org>
Martin Vukovic, <mvukovic at microbotica.es>
Flaviano Tresoldi, <info at swwork.it>
Narcyz Knap, <narcyz at gumed.edu.pl>
Devin Ceartas, <devin@nacredata.com>
COPYRIGHT
Copyright 2015-2020 Microbotica
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.