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)

use MIME::LITE; use strict; use constant cYES => "yes"; # If the email has parameters that can be read if ($valid_email eq cYES) { eval { # Set up the email variables $msg = MIME::Lite->new( From => "$msg_name <$msg_from>", To => "$msg_to", Subject => "$msg_subject", Type => 'multipart/mixed' ) or die "Cannot send the email :\n$!\n"; # Zip and attach reasons file if (defined($missing) && ($missing =~ /[A-Za-z0-9]/)) { &attach_text($missing); } } # Send the Message MIME::Lite->send('smtp', "servername", Timeout=>300, Debug=>1) or die "Error sending email: $!\n"; $msg->send; } ## This sub routine compress the file for added effiency # sub zip_file { # This hold the name of the datafile to compress my $full_file = ""; # This hold the name of the compressed zip file my $zip_file = ""; # Read in the parameter $full_file = "@_"; # This hold the name and path of the file to compress $zip_file = $full_file; # Add on the .zip extension $zip_file = $zip_file.".zip"; # Call system zip to create the compressed file the switch -q = qu +ietly system ("zip -q $zip_file $full_file"); # attach the zipped file &attach_file($zip_file); } ## This sub routine lists and attaches each file # sub attach_file { # Initialise the variable to hold the file to be attached my $attach_zip = ""; $attach_zip = "@_"; # Add the text message part $msg->attach ( Type => 'TEXT', Data => "\n\n\n$attach_zip\n\n\n\t", ) or die "Error adding the zip file : $!\n"; # Open the text file open (ATTACH_FILE, "$attach_zip") or die ("Cannot open attachment file: $attach_zip $!\n"); # Attach the text file $msg->attach( Type => 'BINARY', Path => $attach_zip, Filename => $attach_zip, ) or die "Error attaching zip file: $!\n"; # Close the atachment file close(ATTACH_FILE); } }; ##################### # check out why it failed using eval ###################### if ($@) { $error = $error."Error : The script failed to send the ema +il.\n\n"; $error = $error."From - $msg_name <$msg_from>\n"; $error = $error."To - $msg_to\n"; $error = $error."Subject - $msg_subject\n"; $error = $error."File - $attachfile\n\n"; } }
The code for a perl 5.8 on fedora 6 using sendmail is :
# Send the Message MIME::Lite->send('sendmail',"/usr/sbin/sendmail -t -oi -oe +m") or warn "Error sending email :\n$!\n";

In reply to Re: SMTP Connection error by chime
in thread SMTP Connection error by gpurusho

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.