SendMail Function Failure


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting SendMail Function Failure
# 1  
Old 10-28-2010
SendMail Function Failure

Hi All,

Background: We use SendMail function (given below) to send emails to users. The email address are obtained as ouptut of a stored procedure in sybase.

We have defined a SendMail function as below in a .pm file and it is used in a .pl script.

Code Snippet:
Code:
sub SendMail
{
    my (
         $Message ,
         $Subject ,
         $To,
         $CC
       ) = @_;
    my ($sec, $min, $hour, $mday, $mon, $year) = localtime(time) ;
    my $PgmName = "$hour:$min:$sec" ;
    Log( "\nRecepients To: << $To >>\n" ) ;
    Log( "\nRecepients CC: << $CC >>\n" ) ;
    open(SENDMAIL, "|/usr/lib/sendmail -oi -t")
        || die "Can't fork for sendmail: $!\n";
#Content-Transfer-Encoding: quoted-printable
    print SENDMAIL << "EOF";
From: $MAIL_FROM
Date: $PgmName
To: $To
CC: $CC
Subject: $Subject
Content-Type: text/html; charset="iso-8859-1"
$Message
EOF
close(SENDMAIL) || die "sendmail didn't close nicely";
   if( $? !=0  )
   {
      Log("System Mail Failed");
   }
   else
   {
      Log ("Mail Sent Successfully");
   }
}

The above SendMail is called in a perl script.

Issue:

Lets say we have 10 email address to which emails has to be send, and the 5th email address's mail box is no longer available though the email address is a valid one. Henceforth the sendmail function fails with "
sendmail didn't close nicely " message and email is not send to the rest of the people.

Expected Resolution Options

i) Validate whether the mailbox is still active. OR
ii) Prevent the sendmail from failing & continue to send the mail to the other people.

Kindly provide a possible solution. Thanking All in advance for your time.

Last edited by zaxxon; 10-29-2010 at 02:22 AM..
# 2  
Old 10-31-2010
I had similar problems with sendmail (fails to exit properly and sometimes locks up). I switched to MIME::Lite and all these problems went away.

Also found it a good idea to validate the email addresses (from and to) before trying anything (Email::Valid is pretty easy to use).

I've thrown together an example of what I use below.

Code:
#!/usr/bin/perl
 
use MIME::Lite;
use Email::Valid;
 
...
 
if (!Email::Valid->address($MAIL_FROM)) {
    Log("From email address << $MAIL_FROM >> is invalid\n") ;
    exit ;
}
 
... Other checks here ...
 
my $msg;
 
### Create the multipart "container" to be sent to recipient:
$msg = MIME::Lite->new(
    From      =>$MAIL_FROM,
    To        =>$TO_EMAIL,
    Subject   =>$EMAIL_SUBJECT,
    Type      =>'multipart/mixed'
        ) or die "Error creating multipart container: $!\n";
 
### Add the body part:
$msg->attach(
    Type     =>'TEXT',
    Data     =>$EMAIL_BODY."\n\n"
    ) or die "Error adding the text message part : $!\n";
 
### Add a pdf attachement:
$msg->attach(Type     => 'application/postscript',
    Path     => $TEMP_PDF_FILE,
    Filename => $ATTACH_NAME,
    Disposition => 'attachment'
    );
 
eval { $msg->send('smtp', "my.smtp.server.com", Timeout=>60); };
die "Error: $@" if ($@);
 
...

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Problems host name lookup failure sendmail

Hi I have a problem in sendmail Freebsd when sending emails to yahoo as an example, I get: Sep 5 10:05:43 local50 sm-mta: STARTTLS=client, error: connect failed=-1, SSL_error=1, errno=0, retry=-1 Sep 5 10:05:43 local50 sm-mta: STARTTLS=client: 43926:error:1407742E:SSL... (3 Replies)
Discussion started by: rickyarge92
3 Replies

2. Shell Programming and Scripting

Function - Make your function return an exit status

Hi All, Good Day, seeking for your assistance on how to not perform my 2nd, 3rd,4th etc.. function if my 1st function is in else condition. #Body function1() { if then echo "exist" else echo "not exist" } #if not exist in function1 my all other function will not proceed.... (4 Replies)
Discussion started by: meister29
4 Replies

3. Solaris

Clarifying sendmail configuration - sendmail-client offline

Hi all, I have read about sendmail running as 2 separate process. 1 as a MSP, and the other as the real daemon or MTA. In my current configuration, the sendmail-client is disabled. Both submit.cf and sendmail.cf are left as default untouch I do not specified any mailhost... (3 Replies)
Discussion started by: javanoob
3 Replies

4. Shell Programming and Scripting

Sendmail function

Hi , The default mail/mailx function is not supporting HTML/ Headers. But sendmail does. Can anyone of you please guide me in creating function like 1. Sending HTML Emails. FN_SEND_EMAIL "$MAIL_BODY" "HTML" $MAIL_BODY="<html><table><tr><td>Just</td><td>testing</td></tr></table>" ... (1 Reply)
Discussion started by: Anupam_Halder
1 Replies

5. UNIX for Advanced & Expert Users

Sendmail questions, SCO 5.0.6 sendmail 8.11.0

I am running SCO 5.0.6 and using sendmail 8.11.0 and having issues with smtp authentication. When trying to send mail the following message will kick back. (reason: 530 5.7.1 Authentication required) 530 5.7.1 Authentication required Not sure what needs to be tweeked in sendmail.cf but I... (1 Reply)
Discussion started by: ziggy6
1 Replies

6. Shell Programming and Scripting

Error Message in function causing failure.....

I have a long busybox ash script that has 3 stages. 1. Identify and Capture information on variable data sources, output the information to text file on each data source. 2. Using data from 1 above now actually do data processing on each individual dataset. 3. Produce report. So... (6 Replies)
Discussion started by: tesser
6 Replies

7. UNIX for Dummies Questions & Answers

boot up failure unix sco after power failure

hi power went out. next day unix sco wont boot up error code 303. any help appreciated as we are clueless. (11 Replies)
Discussion started by: fredthayer
11 Replies

8. Shell Programming and Scripting

Passing global variable to a function which is called by another function

Hi , I have three funcions f1, f2 and f3 . f1 calls f2 and f2 calls f3 . I have a global variable "period" which i want to pass to f3 . Can i pass the variable directly in the definition of f3 ? Pls help . sars (4 Replies)
Discussion started by: sars
4 Replies

9. Shell Programming and Scripting

sendmail function

Hi all, Following is the code for sending mail with attachment #! /bin/ksh SUBJ="Send mail from Unix PHDCAP12 " TO=tmp@rediff.com CC=tmp1@rediff.com ( cat << ! To : ${TO} Subject : ${SUBJ} Cc : ${CC} ! cat << ! HOPE THIS WORKS Test123 This sample E-mail message with the Unix... (1 Reply)
Discussion started by: radhika03
1 Replies

10. UNIX for Advanced & Expert Users

Capturing sendmail success/failure?

I am working on a project that will use sendmail to send reports form a shell script. Since these reports are very important and go out at all times of the day, I need to be able to capture if sendmail is unsuccessful or errors out. The emails may have multiple recipients with multiple attachments.... (2 Replies)
Discussion started by: ssracer
2 Replies
Login or Register to Ask a Question