Beefy Boxes and Bandwidth Generously Provided by pair Networks httptech
P is for Practical
 
PerlMonks  

Re: Using Email::Stuff to send SMTP mail through GMail

by jasonk (Parson)
on Sep 19, 2006 at 18:35 UTC ( [id://573820]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Using Email::Stuff to send SMTP mail through GMail

'smtp.gmail.com:465' is not a valid hostname. Since Net::SMTP is a subclass of IO::Socket::INET, you probably want Host => 'smtp.gmail.com', PeerPort => 465, instead.


We're not surrounded, we're in a target-rich environment!

Replies are listed 'Best First'.
Re^2: Using Email::Stuff to send SMTP mail through GMail
by initself (Monk) on Sep 19, 2006 at 18:44 UTC

    I made that change as you suggested but I still get an error message:

    Couldn't connect to smtp.gmail.com at testmail.pl line 16.
    ->send('SMTP', Host => 'smtp.gmail.com', PeerPort => 465, ssl => 1, username => 'mike@mikebaas.com', password => 'x', );
      Well I'm not doing any better than you, although being on Win32 may distort things. Got some error messages though...

      I ended up spliting up the call string in order to intervene in the setup steps:

      my $objst = Email::Stuff ->to('tshinnic@io.com') ->from('tshinnic@gmail.com') ->subject('Test Subject') ->text_body('This is a test.'); # This forces Net::SMTP::SSL to be loaded $objst->using( 'SMTP', ssl => 1 ); # Which allows us to do this ... $IO::Socket::SSL::DEBUG = 1; my $rc = $objst->send('SMTP', ssl => 1, Host => 'smtp.gmail.com', PeerPort => 465, username => 'tshinnic', password => 'xxx', Debug => 1, );
      which finally gets us an actual error message!
      CA file certs/my-ca.pem not found, using CA path instead. IO::Socket::INET configuration failederror:00000000:lib(0):func(0):rea +son(0) at C:/Perl587/site/lib/Email/Send/SMTP.pm line 37
      which is of very little help to me, anyway...

      After taking the same extraordinary measures, what error messages do you see?

        That is exactly the same error message I get now. Off the top of my head, I have no idea what it means. Off to figure it out!
        Doesn't matter if it is on Win32 or *nix, I could not build Email::Stuff onWin32, so I tried it on one of my CentOS testing servers:
        #!/usr/bin/perl use warnings; use strict; use Email::Stuff; my $objst = Email::Stuff ->to('jophnday@wordsnimages.com') ->from('praecipuus@gmail.com') ->subject('Test Subject') ->text_body('This is a test.'); # This forces Net::SMTP::SSL to be loaded $objst->using( 'SMTP', ssl => 1 ); # Which allows us to do this ... $IO::Socket::SSL::DEBUG = 1; my $rc = $objst->send('SMTP', ssl => 1, Host => 'smtp.gmail.com', PeerPort => 465, username => 'praecipuus', password => 'xx***xx', Debug => 1, );
        Result:
        Name "IO::Socket::SSL::DEBUG" used only once: possible typo at emailst +uff.pl line 13. CA file certs/my-ca.pem not found, using CA path instead. IO::Socket::INET configuration failederror:00000000:lib(0):func(0):rea +son(0) at /usr/lib/perl5/site_perl/5.8.7/Email/Send/SMTP.pm line 37
        jdtoronto
      Eail::Stuff seems to be something of a wrapper around a whole lot of otehr modules, there's no problemw ith that, so after your last post I thought, well, let's see what Net::SMTP::SSL does with this:
      #!/usr/bin/perl use warnings; use strict; use Net::SMTP::SSL; my $smtp = Net::SMTP::SSL->new( 'smtp.gmail.com', Port => 465, Timeout => 30, Debug => 1, ); print $@;
      produces:
      Net::SMTP::SSL: Bad service ''
      So I think the problem is deeper again, Net::SMTP::SSL is purely a thing wrapper around Net::SMTP to enable it to use IO::SOCKET::SSL instead of IO::SOCKET::INET.

      I don't have time to try more now, but this might give you some more thngs to follow up.

      jdtoronto

        First off, testing the socket connection to smtp.gmail.com:465 works great using IO::Socket::SSL:

        use IO::Socket::SSL; my $client = IO::Socket::SSL->new("smtp.gmail.com:465"); if ($client) { print $client "GET / HTTP/1.0\r\n\r\n"; print <$client>; close $client; } else { warn "I encountered a problem: ", IO::Socket::SSL::errstr(); }

        Result:

        220 mx.gmail.com ESMTP c18sm62410hub

        Then a really simple test with Net::SMTP::SSL yields a bad result:

        use Net::SMTP::SSL; use Data::Dumper; my $smtps = Net::SMTP::SSL->new("smtp.gmail.com", Port => 465); print Dumper($smtps);

        Result:

        $VAR1 = undef;

        What puzzles me is that these are very established modules. I'll report more here when I know more.

        Indeed, Email::Stuff is just a usability wrapper (I wrote it that way intentionally).

        Trouble with IO::Socket::(Anything) on Win32 would not surprise me at all, there's a few dragons there.

        What Perl distribution are you using?

        The first step might be to just write a simple test script that tries to connect via SSL, then immediately drops the connect once established, to GMail's server and see if that works.

        That would isolate the problem to the connectivity layer. If you can get that working, then lets look at Email::Stuff and friends.

        Until then though, I consider the entire Email:: family to be blameless here.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://573820]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.