Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: SMTP Connection error

by chime (Friar)
on Jan 03, 2007 at 13:01 UTC ( [id://592753]=note: print w/replies, xml ) Need Help??


in reply to SMTP Connection error

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";

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://592753]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2024-04-19 22:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found