By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,631 Members | 892 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,631 IT Pros & Developers. It's quick & easy.

error in Net::SMTP Can't open server

P: 63
Hi, I'm trying some code to send a mail with my script. This is it:

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2. use Net::SMTP;
  3.  
  4. my $smtp_server='62.193.245.15';
  5. my $smtp = Net::SMTP->new($smtp_server) or die "Can't Open server\n";
  6. $smtp->mail('joao.correia@tvn.pt');
  7. $smtp->to('jcor@sapo.pt');
  8. $smtp->auth("joao.correia@tvn.pt","*password*");
  9. $smtp->data();
  10. $smtp->datasend("To: jcor@sapo.pt\n");
  11. $smtp->datasend("From: joao.correia@tvn.pt\n");
  12. $smtp->datasend("Subject: test\n");
  13. $smtp->datasend("\n");
  14. $smtp->datasend("some test text");
  15. $smtp->dataend();
  16.  
  17. $smtp->quit;
My problem is that it allways die when creating the object. It's not possible to create the objectwith the IP instead of smtp."something"?
Is this IP that I have in my thunderbird and it works perfectly!

Am I failing something?

Can someone give me an hand?

Thanks,

Joćo Correia
Jan 28 '08 #1
Share this Question
Share on Google+
13 Replies


numberwhun
Expert Mod 2.5K+
P: 3,503
Hi, I'm trying some code to send a mail with my script. This is it:

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2. use Net::SMTP;
  3.  
  4. my $smtp_server='62.193.245.15';
  5. my $smtp = Net::SMTP->new($smtp_server) or die "Can't Open server\n";
  6. $smtp->mail('joao.correia@tvn.pt');
  7. $smtp->to('jcor@sapo.pt');
  8. $smtp->auth("joao.correia@tvn.pt","*password*");
  9. $smtp->data();
  10. $smtp->datasend("To: jcor@sapo.pt\n");
  11. $smtp->datasend("From: joao.correia@tvn.pt\n");
  12. $smtp->datasend("Subject: test\n");
  13. $smtp->datasend("\n");
  14. $smtp->datasend("some test text");
  15. $smtp->dataend();
  16.  
  17. $smtp->quit;
My problem is that it allways die when creating the object. It's not possible to create the objectwith the IP instead of smtp."something"?
Is this IP that I have in my thunderbird and it works perfectly!

Am I failing something?

Can someone give me an hand?

Thanks,

Joćo Correia
How about this, change this line:

Expand|Select|Wrap|Line Numbers
  1. my $smtp = Net::SMTP->new($smtp_server) or die "Can't Open server\n";
  2.  
to be:

Expand|Select|Wrap|Line Numbers
  1. my $smtp = Net::SMTP->new($smtp_server) or die "Can't Open server: $!\n";
  2.  
and let us know what is printed out for the error after "Can't Open server". That will be the error that is being kicked back.

Regards,

Jeff
Jan 28 '08 #2

numberwhun
Expert Mod 2.5K+
P: 3,503
Just to let you know, when I telnet, it doesn't let me in:

>>telnet 62.193.245.15 25

Connecting To 62.193.245.15...Could not open connection to the host, on port 25:
Connect failed

If this holds true, I don't think it is accepting connections from outside. Is this an internal SMTP server for tvnet.pt?

Regards,

Jeff
Jan 28 '08 #3

P: 63
It should retrieve in my console, right?
I got nothing, I run only this code:
Expand|Select|Wrap|Line Numbers
  1. use Net::SMTP;
  2. my $smtp_server='62.193.245.15';
  3. my $smtp = Net::SMTP->new($smtp_server) or die "Can't Open server: $!\n";
  4. $smtp->quit;
  5.  
and this is my console:
Expand|Select|Wrap|Line Numbers
  1. joao@joao-UBUNTU:~/Desktop$ perl Net_SMTP 
  2. Can't Open server: 
  3. joao@joao-UBUNTU:~/Desktop$ 
Should I see the error in some filehandle, or something?
Jan 28 '08 #4

P: 63
answering to your second post,I use that IP in my thunderbird smtp server and I send mails everywhere, I guess it's the correct smtp server.
Jan 28 '08 #5

numberwhun
Expert Mod 2.5K+
P: 3,503
answering to your second post,I use that IP in my thunderbird smtp server and I send mails everywhere, I guess it's the correct smtp server.
You will have to bear with me as I don't have a ton of experience with this module, but from the documentation on CPAN, why not try this:

Expand|Select|Wrap|Line Numbers
  1.  
  2. $smtp = Net::SMTP->new('mailhost',
  3.                            Hello => 'my.mail.domain',
  4.                            Timeout => 30,
  5.                            Debug   => 1,
  6.                           );
  7.  
If you read the link, you will see what each of the options does for you.

Regards,

Jeff
Jan 28 '08 #6

P: 63
Hi, I decided to use other email account because maybe my smtp vould be with any problem, I don't know.
My code now is this:

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2.  
  3. use Net::SMTP;
  4.  
  5. my $smtp_server='smtp.mail.yahoo.com.br';
  6. my $smtp_to='joao_correia_0509@yahoo.com.br';
  7. my $smtp_auth='joao_correia_0509';
  8. my $smtp_pass='***password****';
  9. my $smtp_mail="yahoo";
  10.  
  11. my $smtp = Net::SMTP->new($smtp_server,
  12.               Timeout => 30,
  13.               Debug => 1,
  14.               ) or die "Can't Open server: $!\n";
  15. $smtp->auth($smtp_auth,$smtp_pass) or die "in auth: $!\n";
  16. $smtp->to($smtp_to) or die "in to: $!\n";
  17. $smtp->data();
  18. $smtp->datasend("test it ");
  19. $smtp->dataend();
  20. print $smtp->domain();
  21. print "it's gone!!!\n";
  22. $smtp->quit;
  23.  
Now it connects to the server but gives a error in the authorization. This is the output with the debug:

Expand|Select|Wrap|Line Numbers
  1. joao@joao-UBUNTU:~/Desktop$ perl Net_SMTP
  2. Net::SMTP>>> Net::SMTP(2.31)
  3. Net::SMTP>>>   Net::Cmd(2.29)
  4. Net::SMTP>>>     Exporter(5.58)
  5. Net::SMTP>>>   IO::Socket::INET(1.29)
  6. Net::SMTP>>>     IO::Socket(1.29)
  7. Net::SMTP>>>       IO::Handle(1.25)
  8. Net::SMTP=GLOB(0x82da17c)<<< 220 smtp108.mail.mud.yahoo.com ESMTP
  9. Net::SMTP=GLOB(0x82da17c)>>> EHLO localhost.localdomain
  10. Net::SMTP=GLOB(0x82da17c)<<< 250-smtp108.mail.mud.yahoo.com
  11. Net::SMTP=GLOB(0x82da17c)<<< 250-AUTH LOGIN PLAIN XYMCOOKIE
  12. Net::SMTP=GLOB(0x82da17c)<<< 250-PIPELINING
  13. Net::SMTP=GLOB(0x82da17c)<<< 250 8BITMIME
  14. in auth: Ficheiro ou directoria inexistente
  15.  
The last line translation is "in auth: file or folder nonexistent", or something similar.

Can you help in this?

Or, in last case, can someone give me another module or something to send a mail from the script?

Thanks,

Joćo
thanks
Jan 29 '08 #7

eWish
Expert 100+
P: 971
I too have not messed with Net::Smtp, I prefer Mail::Sendmail or Mime::Lite. In addition to those, there are many modules for email on CPAN. Here is an excerpt from the Mail::Sendmail module.

Expand|Select|Wrap|Line Numbers
  1.   use Mail::Sendmail;
  2.  
  3.   %mail = ( To      => 'you@there.com',
  4.             From    => 'me@here.com',
  5.             Message => "This is a very short message"
  6.            );
  7.  
  8.   sendmail(%mail) or die $Mail::Sendmail::error;
  9.  
  10.   print "OK. Log says:\n", $Mail::Sendmail::log;
What OS are you using? Don't think that the authentication works correctly on a windows machine. If that is the case that you might look at Net::SMTP::TLS.

--Kevin
Jan 30 '08 #8

numberwhun
Expert Mod 2.5K+
P: 3,503
The only time I did play with this module, it was with a mail server that was internal and on the network that I was connected with. So, connecting and sending email was a breeze and it worked like a charm, I must say. Unfortunately, I haven't done anything with authentication, although I should. I would check the module(s) that Kevin suggested and see if any of them work for you.

Regards,

Jeff
Jan 30 '08 #9

P: 63
I'm using Ubuntu 7.04

I'll take a look in the modules you told me.
But to use Mail::SendMail I'll have to configure "sendmail" in my ubuntu, right?
I'll try that

Thanks for your help,

Joćo
Jan 30 '08 #10

P: 63
I now trying to use this module MIME::Lite;

Seems pretty easy but doesn't work either.
my code is just:
Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2.  
  3. use MIME::Lite;
  4.  
  5.     ### Create a new single-part message, to send a GIF file:
  6.     $msg = MIME::Lite->new(
  7.         From     =>'joao.correia.tvnet@gmail.com',
  8.         To       =>'jcor@net.sapo.pt',
  9.         Subject  =>'Helloooooo, nurse!',
  10.         Data     =>"How's it goin', eh?"
  11.     );
  12. MIME::Lite->send( 'smtp','smtp.gmail.com',Timeout=>60,
  13.           Debug=>1);
  14.  
  15. $msg ->send();
  16.  
  17. print" a mensagem foi enviada com sucesso\n";
  18.  
The debugger gives me this:

Expand|Select|Wrap|Line Numbers
  1. joao@joao-UBUNTU:~/Desktop$ perl Send
  2. MIME::Lite::SMTP>>> MIME::Lite::SMTP
  3. MIME::Lite::SMTP>>>   Net::SMTP(2.31)
  4. MIME::Lite::SMTP>>>     Net::Cmd(2.29)
  5. MIME::Lite::SMTP>>>       Exporter(5.58)
  6. MIME::Lite::SMTP>>>     IO::Socket::INET(1.29)
  7. MIME::Lite::SMTP>>>       IO::Socket(1.29)
  8. MIME::Lite::SMTP>>>         IO::Handle(1.25)
  9. MIME::Lite::SMTP=GLOB(0x83fae0c)<<< 220 mx.google.com ESMTP m5sm11074509gve.11
  10. MIME::Lite::SMTP=GLOB(0x83fae0c)>>> EHLO localhost.localdomain
  11. MIME::Lite::SMTP=GLOB(0x83fae0c)<<< 250-mx.google.com at your service, [81.193.137.56]
  12. MIME::Lite::SMTP=GLOB(0x83fae0c)<<< 250-SIZE 28311552
  13. MIME::Lite::SMTP=GLOB(0x83fae0c)<<< 250-8BITMIME
  14. MIME::Lite::SMTP=GLOB(0x83fae0c)<<< 250-STARTTLS
  15. MIME::Lite::SMTP=GLOB(0x83fae0c)<<< 250 ENHANCEDSTATUSCODES
  16. MIME::Lite::SMTP=GLOB(0x83fae0c)>>> MAIL FROM:<joao.correia.tvnet@gmail.com>
  17. MIME::Lite::SMTP=GLOB(0x83fae0c)<<< 530 5.7.0 Must issue a STARTTLS command first m5sm11074509gve.11
  18. SMTP mail() command failed: 
  19. 5.7.0 Must issue a STARTTLS command first m5sm11074509gve.11
  20.  
Do you guys knows what's the problem here?

And do I allways have to use an "external smtp" (if you understand what I mean)? is not possible to simply send an e-mail for localhost, something like that? (maybe this is just a dummy question, I'm not really sure)

Thanks for your time anyway

Joćo
Jan 30 '08 #11

numberwhun
Expert Mod 2.5K+
P: 3,503
Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2.  
  3. use MIME::Lite;
  4.  
  5.     ### Create a new single-part message, to send a GIF file:
  6.     $msg = MIME::Lite->new(
  7.         From     =>'joao.correia.tvnet@gmail.com',
  8.         To       =>'jcor@net.sapo.pt',
  9.         Subject  =>'Helloooooo, nurse!',
  10.         Data     =>"How's it goin', eh?"
  11.     );
  12. MIME::Lite->send( 'smtp','smtp.gmail.com',Timeout=>60,
  13.           Debug=>1);
  14.  
  15. $msg ->send();
  16.  
  17. print" a mensagem foi enviada com sucesso\n";
  18.  

Where do you do authentication? I would not doubt that when accessing an external service like this, that you are going to have to do some sort of authentication with a user name and password. If not, then anybody, account or not, could send email through there. You should read up on each module and how they handle the authentication. I think that has been the issue all along, that you aren't authenticating to send/receive email.

Regards,

Jeff
Jan 30 '08 #12

P: 63
Hi guys,
My script is working now,
my code is (adapted from one from de internet):

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2. use strict;
  3. use MIME::Lite;
  4.  
  5. #
  6. $to = "joao.correia.tvnet\@gmail.com";
  7. $from = "joao_correia_0509\@yahoo.com.br";
  8. $subject = "Consegui!!!! Email enviado através de um script Perl";
  9. $message = "Se ler esta mensagem é porque estį mesmo a funcionar!!!";
  10.  
  11.  
  12. # send email
  13. email($to, $from, $subject, $message);
  14.  
  15. # email function
  16. sub email {
  17.      # get incoming parameters
  18.      local ($to, $from, $subject, $message) = @_;
  19.  
  20.     # create a new message
  21.     $msg = MIME::Lite->new(
  22.         From => $from,
  23.         To => $to,
  24.         Subject => $subject,
  25.         Data => $message
  26.     );
  27.  
  28.  # send the email
  29.     MIME::Lite->send('smtp', 
  30.           'smtp.mail.yahoo.com.br', Timeout => 60, Debug =>1,
  31.           AuthUser=>'joao_correia_0509', AuthPass=>'***pass***');
  32.  
  33.    $msg->send();
  34.  
  35. }
  36.  
thanks again for your help

Joćo
Jan 31 '08 #13

numberwhun
Expert Mod 2.5K+
P: 3,503
Now, if you were to investigate the documentation for Net::SMTP, you would probably see something similar to allow you to put the authentication user name and pwd in there as well.

Regards,

Jeff
Jan 31 '08 #14

Post your reply

Sign in to post your reply or Sign up for a free account.