Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Send Email From Gmail

by Adamba (Sexton)
on Jun 19, 2010 at 10:13 UTC ( #845523=perlquestion: print w/ replies, xml ) Need Help??
Adamba has asked for the wisdom of the Perl Monks concerning the following question:

Hey,

I'm trying to send an email from gmail (SMTP) to another mail using Email::Simple and Net::SMTP::TLS. I guess i'm doing something wrong cause I always get a connection timeout error.

I've also tried to use Email::Sender::Transport::SMTP::TLS, but I get an error that my Class::MOP is only version 0.84 and verion 0.94 is required, and ppm says Class::MOP is up-to-date. tried to install it with cpanm but it fails on testing....

Help anyone?

use strict; use warnings; use Email::Simple; use Net::SMTP::TLS; #use Email::Sender::Transport::SMTP::TLS; #my $mailer = Email::Sender::Transport::SMTP::TLS->new( # host => 'smtp.gmail.com', # port => 465, # username => 'username@gmail.com', # password => 'password', # ); my $sender = new Net::SMTP::TLS( Hello => 'smtp.gmail.com', Port => 465, User => 'username@gmail.com', Password => 'password', ); my $message = Email::Simple->create( header => [ From => 'you@gmail.com', To => 'someone@example.com', Subject => 'Test Gmail', ], body => 'Content.', ); # eval { # $mailer->send($message, { # from => 'you@gmail.com', # to => [ 'someone@example.com' ], # } ); # }; # die "Error sending email: $@" if $@; $sender->mail('you@gmail.com'); $sender->to('someone@example.com'); $sender->data; $sender->datasend($message); $sender->datasend; $sender->quit;

Comment on Send Email From Gmail
Download Code
Re: Send Email From Gmail
by Khen1950fx (Canon) on Jun 19, 2010 at 11:08 UTC
    Go ahead and update Class::MOP. I think that you need to explicitly name the mail host:
    my $sender = new Net::SMTP::TLS( 'some.mail.host', Hello => 'smtp.gmail.com', Port => 465, User => 'username@gmail.com', Password => 'password',
Re: Send Email From Gmail
by Adamba (Sexton) on Jun 19, 2010 at 11:53 UTC

    Update! I've succeded sending mail from gmail with Net::SMTP::SSL

    Now I need to send from hotmail, as I read it uses the TLS connection... I've tried to use again the Net::SMTP:TLS module, but again I get a connection timed out error...

    Anyone Succeded sending email from Hotmail using Net::SMTP::TLS?

    use strict; use warnings; use Email::Simple; use Net::SMTP::SSL; use Net::SMTP::TLS; my $to = 'someone@example.com'; my $msg = "Test"; my $from = 'username@hotmail.com>'; my $smtphost = 'smtp.live.com'; my $subject = 'Test Hotmail'; my $Hotmail = new Net::SMTP::TLS( 'localhost', Hello => 'smtp.live.com', Port => 25, Debug => 1, User => 'username@hotmail.com', Password=> 'password' ); $Hotmail->mail($from); $Hotmail->to($to); $Hotmail->data(); $Hotmail->datasend("From: " . $from . "\n"); $Hotmail->datasend("To: " . $to . "\n"); $Hotmail->datasend("Subject: " . $subject . "\n"); $Hotmail->datasend("\n"); $Hotmail->datasend($msg . "\n"); $Hotmail->dataend(); $Hotmail->quit;
Re: Send Email From Gmail
by Krambambuli (Deacon) on Jun 19, 2010 at 12:19 UTC
    If using Net::SMTP::TLS, the 'Hello' param says who _you_ are. So try something like
    my $mailer = new Net::SMTP::TLS( 'smtp.gmail.com', Hello => 'the _host_name_you_are_coming_from', [...]

      Thanks! but it's still giving me the connection timeout error....

        It's working!

        changed the port to 587, now everything works!

        Thank you monks! :)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://845523]
Approved by Old_Gray_Bear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2014-07-26 13:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (177 votes), past polls