473,287 Members | 1,643 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

error in Net::SMTP Can't open server

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
13 6760
numberwhun
3,509 Expert Mod 2GB
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 Expert Mod 2GB
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
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
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 Expert Mod 2GB
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
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 Expert 512MB
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 Expert Mod 2GB
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
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
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 Expert Mod 2GB
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
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 Expert Mod 2GB
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
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
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
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
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
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
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
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
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
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...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...

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.