SendMail.pm: smtp and gmail

Discussion in 'Perl Misc' started by Davidcollins001@gmail.com, May 25, 2007.

  1. Guest

    Hi,

    I have just found the SendMail.pm perl module. I have been using it
    for about a week to email myself backups of my important documents. I
    am currently using it from withing a university network so setting up
    the smtp didn't require much.

    I would like to be able to use it to sent mail using my gmail account.
    I have done a bit of googling and so far I have come up with one post
    saying that this module doesn't have ssl yet, but that was two years
    or so ago. Is this still the case? Or is it possible to connect to the
    gmail smtp server?

    Thanks
    , May 25, 2007
    #1
    1. Advertising

  2. On May 25, 5:15 am, wrote:
    > Hi,
    >
    > I have just found the SendMail.pm perl module. I have been using it
    > for about a week to email myself backups of my important documents. I
    > am currently using it from withing a university network so setting up
    > the smtp didn't require much.
    >
    > I would like to be able to use it to sent mail using my gmail account.
    > I have done a bit of googling and so far I have come up with one post

    huh, what...
    http://www.google.com/search?q=SMTP SSL Perl

    > saying that this module doesn't have ssl yet, but that was two years


    Net::SMTP::SSL.

    > or so ago. Is this still the case? Or is it possible to connect to the
    > gmail smtp server?


    Since you are using gmail, you might as well say screw plain ol' SMTP
    and use one of the gmail modules. They'll allow you to "easily" take
    advantage of the "features" provided by our good friends at gmail.
    Skye Shaw!@#$, May 28, 2007
    #2
    1. Advertising

  3. Guest

    Thankyou, I usually google quite well. I had found the net modules but
    didn't realise I could use them for this purpose. Here come automated
    email backups for my docs!

    :)
    , May 29, 2007
    #3
  4. Guest

    So, I thought this was going to be quite easy, and it seems like it
    should be but I keep getting an error:

    $ Could not connect to smtp.googlemail.com


    Here is my code:

    Code:
    use Net::SMTP::SSL;
    
    my $smtpserver='smtp.googlemail.com';
    my $smtpport=465;
    
    $smtp = Net::SMTP::SSL->new(Host => $smtpserver,
    Port => $smtpport,
    debug=> 1) ||
    die "Could not connect to $smtpserver; $!";
    [\CODE]
    
    Is there something that I am missing? I dont get any extra info from
    including the debug flag.
    Thanks
    , May 30, 2007
    #4
  5. Timo Jokinen Guest

    wrote:
    > So, I thought this was going to be quite easy, and it seems like it
    > should be but I keep getting an error:
    >
    > $ Could not connect to smtp.googlemail.com
    >
    >
    > Here is my code:
    >
    >
    Code:
    > use Net::SMTP::SSL;
    >
    > my $smtpserver='smtp.googlemail.com';
    > my $smtpport=465;
    >
    >    $smtp = Net::SMTP::SSL->new(Host => $smtpserver,
    >  			       Port => $smtpport,
    >  			       debug=> 1) ||
    > 	die "Could not connect to $smtpserver; $!";
    > [\CODE]
    >
    > Is there something that I am missing? I dont get any extra info from
    > including the debug flag.
    > Thanks
    >[/color]
    
    Are you sure for port? Default port for SSL is 443
    
    br
    -timppa
    Timo Jokinen, May 30, 2007
    #5
  6. Guest

    So, I thought this was going to be quite easy, and it seems like it
    should be but I keep getting an error:

    $ Could not connect to smtp.googlemail.com


    Here is my code:

    Code:
    use Net::SMTP::SSL;
    
    my $smtpserver='smtp.googlemail.com';
    my $smtpport=465;
    
    $smtp = Net::SMTP::SSL->new(Host => $smtpserver,
    Port => $smtpport,
    debug=> 1) ||
    die "Could not connect to $smtpserver; $!";
    [\CODE]
    
    Is there something that I am missing? I dont get any extra info from
    including the debug flag.
    Thanks
    , May 30, 2007
    #6
  7. Guest

    , May 30, 2007
    #7
  8. Guest

    , May 30, 2007
    #8
  9. wrote:

    >>
    >> Are you sure for port? Default port for SSL is 443
    >>

    >
    > The gmail page says that their smtp server uses ports 465 or 587,
    > neither work for me (I tried 443 and it was the same too)
    > (http://mail.google.com/support/bin/answer.py?answer=13287)


    587 usually requires TLSfollowed by an SMTP AUTH, not SSL - and it certainly
    accepts an initial connection from telnet.

    465 I think is the one that you want for SSL - that is accepting connections
    too and it looks like an SSL connect.

    Cheers

    Tim
    Tim Southerwood, May 30, 2007
    #9
  10. <> wrote:

    > I keep getting an error:
    >
    > $ Could not connect to smtp.googlemail.com

    ^^^^^^^^^^


    > $smtp = Net::SMTP::SSL->new(Host => $smtpserver,
    > Port => $smtpport,
    > debug=> 1) ||
    > die "Could not connect to $smtpserver; $!";

    ^^^^

    Where is the semicolon and the rest of the message?


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
    Tad McClellan, May 30, 2007
    #10
  11. Guest

    I just tested sending from gmails smtp server using kmail with the
    above settings and it worked fine. I seem to be able to connect using
    IO:Socket:SSL, but not using Net::SMTP::SSL
    , May 30, 2007
    #11
  12. On Wed, 30 May 2007 11:52:20 +0300,
    Timo Jokinen <> wrote:
    > wrote:
    >> So, I thought this was going to be quite easy, and it seems like it
    >> should be but I keep getting an error:
    >>
    >> $ Could not connect to smtp.googlemail.com
    >>
    >>
    >> Here is my code:
    >>
    >>
    Code:
    >> use Net::SMTP::SSL;
    >>
    >> my $smtpserver='smtp.googlemail.com';
    >> my $smtpport=465;
    >>
    >>    $smtp = Net::SMTP::SSL->new(Host => $smtpserver,
    >>  			       Port => $smtpport,
    >>  			       debug=> 1) ||
    >> 	die "Could not connect to $smtpserver; $!";
    >> [\CODE]
    >>
    >> Is there something that I am missing? I dont get any extra info from
    >> including the debug flag.
    >> Thanks
    >>[/color]
    >
    > Are you sure for port? Default port for SSL is 443[/color]
    
    Euhm.. no. 443 is normally used for HTTPS, i.e. HTTP over SSL. SMTP over
    SSL is normally done on port 465. smtp.googlemail.com also accepts port
    587.
    
    To the OP: You're not using the Net::SMTP(::SSL) API as it is documented
    though.  While it might have been a bit more consistent if the hostname
    also required a tag; it doesn't. The hostname is the first argument
    to new(). So:
    
    my $smtp = Net::SMTP::SSL->new($smtpserver, Port => $smtpport)
    or die;
    
    should work for you.
    
    
    Martien
    --
    |
    Martien Verbruggen      | I used to have a Heisenbergmobile. Every time
    | I looked at the speedometer, I got lost.
    |
    Martien verbruggen, May 30, 2007
    #12
  13. Guest

    Hi Martien, I have tried both, initially without using the Host label
    (I thought it might need it since that would seem logical) but I still
    get a cannot connect.

    Hi Tad, I deleted the rest of the message because it only says what
    line the error is on, which is the line of code containing
    Net::SMTP::SSL
    , May 31, 2007
    #13
  14. On 31 May 2007 01:08:01 -0700,
    <> wrote:
    > Hi Martien, I have tried both, initially without using the Host label
    > (I thought it might need it since that would seem logical) but I still
    > get a cannot connect.


    Next time, please reply in context, i.e. to the post that you're
    replying to.

    I get a very distinct difference between the following two:

    $ perl -MNet::SMTP::SSL -wle \
    'Net::SMTP::SSL->new("smtp.googlemail.com", Port => 465) and exit or die'

    and

    $ perl -MNet::SMTP::SSL -wle \
    'Net::SMTP::SSL->new(Host => "smtp.googlemail.com", Port => 465) and exit or die'

    The top one exits, the bottom one dies. This tells me that the top one
    successfully connected, and the bottom one failed to connect. Looking at
    the code for Net::SMTP::SSL also tells me that the bottom one is
    incorrect.

    If you get exactly the same response in both cases something esle is
    wrong. Are you SURE you tried the correct combination of code, hostname
    and port?

    If you did, I suggest that there is something wrong with your network.
    You're not behind a firewall that's blocking this, are you?

    Martien
    --
    |
    Martien Verbruggen | Unix is user friendly. It's just selective
    | about its friends.
    |
    Martien verbruggen, Jun 2, 2007
    #14
  15. On 2007-05-30 10:42, Tim Southerwood <> wrote:
    > wrote:
    >>> Are you sure for port? Default port for SSL is 443


    443 is HTTPS, as others already noted.

    >> The gmail page says that their smtp server uses ports 465 or 587,
    >> neither work for me (I tried 443 and it was the same too)
    >> (http://mail.google.com/support/bin/answer.py?answer=13287)

    >
    > 587 usually requires TLSfollowed by an SMTP AUTH, not SSL - and it certainly
    > accepts an initial connection from telnet.


    That's the recommended way for submitting mail.


    > 465 I think is the one that you want for SSL - that is accepting connections
    > too and it looks like an SSL connect.


    This one is considered obsolete. Google probably still supports it for
    compatibility with MS Outlook.

    If you can, use port 587 + STARTTLS, not port 465.


    A very nice tool for testing SMTP connections and also for sending mail,
    is "swaks", the swiss army knife for smtp. It is written in perl and you
    can use it on the command line to send mail, e.g., like this:

    swaks -s smtp.googlemail.com -tlso -au $username -ap $password -t
    $recipient -f $sender --timeout 10m

    works for me (except that Gmail doesn't seem to like the "quit" command
    - it just sits there and waits until swaks kills the connection)

    Or you can modify it to suit your tastes.

    You can get swaks from http://jetmore.org/john/code/#swaks and it is
    also included in some Linux distributions (e.g., Debian). To use TLS,
    you also need to install Net::SSLeay.

    hp


    --
    _ | Peter J. Holzer | I know I'd be respectful of a pirate
    |_|_) | Sysadmin WSR | with an emu on his shoulder.
    | | | |
    __/ | http://www.hjp.at/ | -- Sam in "Freefall"
    Peter J. Holzer, Jun 10, 2007
    #15
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Hmmm...
    Replies:
    4
    Views:
    2,097
    ChrisO
    Sep 6, 2004
  2. peterson
    Replies:
    0
    Views:
    708
    peterson
    Dec 30, 2003
  3. sugapablo
    Replies:
    0
    Views:
    2,148
    sugapablo
    Sep 21, 2007
  4. Andrzej Adam Filip
    Replies:
    0
    Views:
    4,078
    Andrzej Adam Filip
    Mar 31, 2008
  5. John W. Long
    Replies:
    3
    Views:
    123
    Hugh Sasse Staff Elec Eng
    Aug 26, 2003
Loading...

Share This Page