gpurusho has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,
Please help this novice out.
-Ganesh

My Environment: Windows 2000, perl, v5.8.7

Problem: Connection to SMTP server doe not work

Error Reported :: "Failed to connect to mail server: Unknown error"


History
=========

I am trying to conect to a SMTP server to send otu emails.I have been using this script of mine for a more tha 3 months and I haven't had any problems. Starting 3 days back, I am no longer able to connect to the SMTP server and the scripts exists with te error "Failed to connect to mail server: Unknown error". The same script runs fine on another desktop. Is there some setting issues on my desktop. If so can you monks help me figure this out?



Code
========

package MAILER; BEGIN { } use MIME::Lite; use Net::SMTP; sub send_mail { ### Adjust sender, recipient and your SMTP mailhost # my ($subject, $mail_host, $messageBody, $to_address, $date, $cc_ +address, $my_file_zip) = @_; ### Send the Message MIME::Lite->send('smtp', $mail_host, Timeout=>60); $msg->send; my $from_address = ''; ### Adjust subject and body message ### Adjust the filenames my $your_file_zip = "Report_$date.html"; ### Create the multipart container $msg = MIME::Lite->new ( From => $from_address, To => $to_address, Subject => $subject, Type =>'multipart/mixed' ) or die "Error creating multipart container: $!\n"; ### Add the text message part $msg->attach ( Type => 'TEXT', Data => $messageBody ) or die "Error adding the text message part: $!\n"; ### Add the GIF file ### Add the ZIP file $msg->attach ( Type => 'application/zip', Path => $my_file_zip, Filename => $your_file_zip, Disposition => 'attachment' ) or die "Error adding $file_zip: $!\n"; ### Send the Message MIME::Lite->send('smtp', $mail_host,Timeout=>60); $msg->send; return 0; } return 1; END { }

Replies are listed 'Best First'.
Re: SMTP Connection error
by quester (Vicar) on Jan 03, 2007 at 00:15 UTC
    1. The easiest thing to try would be to telnet to port 25 on the mail server from the desktop where the script fails. This wil check your connectivity with the mail server. Microsoft has a knowledge base article with the details.

    2. You might want to check if the mail server logs show any errors that contain the IP of the workstation where the script fails.

    3. You could try downloading a protocol analyzer that will run on your Windows desktop, such as Wireshark . This will show you the whole conversation between the script and the mail server, including error messages that might be returned by the mail server. If the problem isn't obvious, do the same thing on the desktop where the script works and compare the results.

    P.S. The commands in the Microsoft article are valid for Sendmail and other open source mail servers as well as for the Microsoft mail server line.

      Thanks to all you had replied. I finally figured this out. Looks like it was a Macfee setting that did not allow me to connect ot port 25. Thanks a lot for all your time .

      -Ganesh
Re: SMTP Connection error
by ferreira (Chaplain) on Jan 03, 2007 at 10:01 UTC

    When you're using Net::SMTP, you may get gobs of information by turning the debug on. This way you're going to see all conversation between your Perl script and the server and may eventually figure out what's going wrong.

    I think the only change you need to do is:

    MIME::Lite->send('smtp', $mail_host, Timeout=>60, Debug=>1); ^^^^^^^^^^

    even though I've never used MIME::Lite, but I think it should only pass the arguments Timeout=>60, Debug=>1 to Net::SMTP constructor and then start being verbose.

Re: SMTP Connection error
by chime (Friar) on Jan 03, 2007 at 13:01 UTC
    Hi This might help.

    The code is wrapped in an eval statement and the sendmail part will print out an error, and has a timeout function.

    Hopfully looking at some one elses code will help and this code is easly moved across different servers and is stable.

    (This is just cut from my code so you will have to replace variables, add modules etc)

    The code for a perl 5.8 on fedora 6 using sendmail is :