Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

Perl Programming Language

SendMail.pm: smtp and gmail


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

On May 25, 5:15 am, Davidcollins@gmail.com 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.
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!

:)

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

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

br
-timppa

> 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)

Davidcollins@gmail.com 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

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
On Wed, 30 May 2007 11:52:20 +0300,
        Timo Jokinen <jokinent@kolumbus.fi.invalid> wrote:

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.
                        |

Davidcollins@gmail.com <Davidcollins@gmail.com> 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
    t@augustmail.com                   Perl programming
    Fort Worth, Texas

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

On 31 May 2007 01:08:01 -0700,
        Davidcollins@gmail.com <Davidcollins@gmail.com> 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.
                        |

On 2007-05-30 10:42, Tim Southerwood <t@dionic.net> wrote:

> Davidcollins@gmail.com 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.
| |   | h@hjp.at         |
__/   | http://www.hjp.at/ |      -- Sam in "Freefall"

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc