mailx issue -

Hi,

I am sending mail inside my script based on various conditions.

Here is the problem,

when there are more than one condion at a time, the mailx adds the messages into one ( at the time of the second mail)

example:

inner_fn ()
{
  if [ $a -eq 5 ]; then 
   echo "inner function mail" | mailx -s "sub2" "some1@somedomain.com"
  fi
}

outer_fn ()
{
a=5

if [ $a -lt 6 ];then
 echo "outer function mail" | mailx -s "sub1" "some1@somedomain.com"
 inner_fn
fi
}

when I run this, I receive two mails with messages & subject like below.

i.e the outermail message is still there in the second mail.

how can i resolve this and what could be the reason behind this.!!!

Thanks.

You have assigned the value of a to 5.

The condition for outer loop is 'a' should be less than 6 and condition for inner loop is 'a' should be equal to 5.

Hence both the loops are succeeding and you are getting two mails!

i'm not sure but i think you need to clear you mail queue since your calling it from a sub process.

try redirecting that body of letter instead of just echoing or try putting it in a variable

inner_fn ()
{
  if [ $a -eq 5 ]; then 
   echo "inner function mail" > mail1
   mailx -s "sub2" "some1@somedomain.com" < mail1
  fi
}

outer_fn ()
{
a=5

if [ $a -lt 6 ];then
 echo "outer function mail" > mail2
 mailx -s "sub1" "some1@somedomain.com" < mail2
 inner_fn
fi
}

Hi,

The mail queue problem could be possible but I tried the above solution but unfortunately it didnt work.

How can I clear the mail Queue?