Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^2: Network Unreachable issue while sending email using PERL (gmail)

by manojsagar (Initiate)
on Oct 12, 2017 at 19:16 UTC ( [id://1201257]=note: print w/replies, xml ) Need Help??


in reply to Re: Network Unreachable issue while sending email using PERL (gmail)
in thread Network Unreachable issue while sending email using PERL (gmail)

I managed to resolve it using Email::Sender::Transport::SMTP

#!/usr/bin/perl use strict; use warnings; use Email::Sender::Transport::SMTP; use Email::Sender::Simple qw(sendmail); my $smtpserver = 'smtp.gmail.com'; my $smtpport = 587; my $smtpuser = 'xxxxxxxx@gmail.com'; my $smtppassword = 'xxxxxxxxx'; my $transport = Email::Sender::Transport::SMTP->new({ host => $smtpserver, ssl => 'starttls', port => $smtpport, sasl_username => $smtpuser, sasl_password => $smtppassword, debug => 1, }); my $email = Email::Simple->create( header => [ To => 'xxxxxxxxxx', From => 'xxxxxx@gmail.com', Subject => 'Hi!', ], body => "This is my message\n", ); sendmail($email, { transport => $transport });
  • Comment on Re^2: Network Unreachable issue while sending email using PERL (gmail)
  • Download Code

Replies are listed 'Best First'.
Re^3: Network Unreachable issue while sending email using PERL (gmail)
by 1nickt (Canon) on Oct 12, 2017 at 19:46 UTC

    It's also a nice solution, one I have used in the past because you can wrap the Transport agent code in its own module so the credentials and whatnot are not exposed in the application code.

    use Email::Sender::Simple qw(sendmail); use My::Email::TransportAgent; # returns instance of Email::Sender::Tr +ansport::SMTP ... sendmail( $email, { transport => My::Email::TransportAgent->new } );

    (Or create My::Email::Sender and wrap the whole thing ...)


    The way forward always starts with a minimal test.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1201257]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2024-04-20 02:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found