473,513 Members | 2,456 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

error in Net::SMTP Can't open server

63 New Member
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
13 6777
numberwhun
3,509 Recognized Expert Moderator Specialist
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
3,509 Recognized Expert Moderator Specialist
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
jcor
63 New Member
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
jcor
63 New Member
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
3,509 Recognized Expert Moderator Specialist
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
jcor
63 New Member
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
971 Recognized Expert Contributor
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
3,509 Recognized Expert Moderator Specialist
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
jcor
63 New Member
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
jcor
63 New Member
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
3,509 Recognized Expert Moderator Specialist
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
jcor
63 New Member
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
3,509 Recognized Expert Moderator Specialist
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

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

Similar topics

0
3051
by: Almir | last post by:
I hate this Net::SMTP stuff, everything works fine but for the suject field. I see no way of having it show in an email when sent. Has anyone had this problem, can anyone explain why there are no...
2
13692
by: RandRace | last post by:
I'm having some problems with a little script i wrote using net::smtp. I originally wrote it in linux where it works perfectly. I tried to use it from windows the other day and it doesn't work. It...
0
1319
by: peterson | last post by:
I was trying to send asp.net-smtp mail of UTF-8 unicode international character contents. When I opened the mailbox contents was broken. I am using html format too. Am I missing something?
1
1807
by: neog | last post by:
I'm having a problem with Net::Smtp. Does the datasend() method have problems sending strings containing single quotes? Like I stored the string "Germany's biggest bank, hired" in a hash and it...
4
2351
by: patrickinminneapolis | last post by:
Hi guys, I'm trying to write an emailer, but I can't manage to construct the object properly. Here's what I've got: #!/usr/local/bin/perl -w use Net::SMTP; $smtp =...
1
8488
by: =?Utf-8?B?V0o=?= | last post by:
Hi, I'm looking for a ASP.NET open source social network software to build a web-site. so far, I have no luck. If you have any information, can you help? Thanks. WJ
5
5286
by: jimhill10 | last post by:
I have a perl script that creates an email attachment file from POST data on a web page. This works just fine. I want to customize the email body to contain all of the text data from the file...
1
2673
by: wootmaster | last post by:
I'm writing a script that will run a few tests on a given mail server, it's meant to test to see if VRFY and EXPN is enabled or not. However, when I use "verify" to test to see if VRFY is enabled on...
5
7309
by: veralee | last post by:
I'm in dire need to use Net::SMTP. The server no longer uses "sendmail". I found an example of using Net::SMTP but I have to also include a user name and password for the server. The host provided...
0
7260
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7160
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7384
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
5685
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4746
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3233
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3222
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
799
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
456
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.