Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > SendMail.pm: smtp and gmail

Reply
Thread Tools

SendMail.pm: smtp and gmail

 
 
Davidcollins001@gmail.com
Guest
Posts: n/a
 
      05-30-2007
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

 
Reply With Quote
 
 
 
 
Martien verbruggen
Guest
Posts: n/a
 
      05-30-2007
On Wed, 30 May 2007 11:52:20 +0300,
Timo Jokinen <(E-Mail Removed)> wrote:
> http://www.velocityreviews.com/forums/(E-Mail Removed) 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
>>

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


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.
|
 
Reply With Quote
 
 
 
 
Davidcollins001@gmail.com
Guest
Posts: n/a
 
      05-31-2007
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

 
Reply With Quote
 
Martien verbruggen
Guest
Posts: n/a
 
      06-02-2007
On 31 May 2007 01:08:01 -0700,
(E-Mail Removed) <(E-Mail Removed)> 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.
|
 
Reply With Quote
 
Peter J. Holzer
Guest
Posts: n/a
 
      06-10-2007
On 2007-05-30 10:42, Tim Southerwood <(E-Mail Removed)> wrote:
> (E-Mail Removed) 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/a...y?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.
| | | (E-Mail Removed) |
__/ | http://www.hjp.at/ | -- Sam in "Freefall"
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problems sending mail with gmail and SMTP Mikael H. Ruby 1 02-21-2011 03:50 PM
Accessing GMail account from GMail Groups Ramkumar Computer Support 2 09-25-2005 09:21 AM
gmail blocks .rar files from non-gmail address kritaly Computer Support 3 08-18-2005 12:00 AM
ruby smtp and gmail ruby talk Ruby 5 05-17-2005 01:01 PM
6 gmail accounts available, post your email here or to gmail@thing.dyndns.org thing NZ Computing 6 12-01-2004 11:40 PM



Advertisments