SendMail.pm: smtp and gmail

D

Davidcollins001

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
 
S

Skye Shaw!@#$

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

Davidcollins001

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!

:)
 
D

Davidcollins001

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
 
T

Timo Jokinen

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
[/QUOTE]

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

br
-timppa
 
D

Davidcollins001

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
 
T

Tad McClellan

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?
 
D

Davidcollins001

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
 
M

Martien verbruggen

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
[/QUOTE]

Are you sure for port? Default port for SSL is 443[/QUOTE]

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
 
D

Davidcollins001

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
 
M

Martien verbruggen

On 31 May 2007 01:08:01 -0700,
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
 
P

Peter J. Holzer

443 is HTTPS, as others already noted.
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,202
Messages
2,571,057
Members
47,667
Latest member
DaniloB294

Latest Threads

Top