Sunday, September 13, 2009

Sending EMail Unix Code


## Parameter passed to Oracle Apps is copied into a local variable
P_PARAM=$1
echo "Parameters passed by Apps to the shell script"
echo $P_PARAM
##The parameters as supplied by User, after removing the default Oracle Apps Parameters.
P_USER_PARAM=`echo $P_PARAM|cut -d" " -f 9-`
echo "\nParameters supplied by the user"
echo $P_USER_PARAM
##Extracting indivdual parameters from the user supplied params, using " as the delimiter
P_TO_ID=`echo $P_USER_PARAM|cut -d'"' -f 2`
P_CC_ID=`echo $P_USER_PARAM|cut -d'"' -f 4`
P_SUBJECT=`echo $P_USER_PARAM|cut -d'"' -f 6`
P_BODY_1=`echo $P_USER_PARAM|cut -d'"' -f 8`
P_BODY_2=`echo $P_USER_PARAM|cut -d'"' -f 10`
P_FILE_PATH=`echo $P_USER_PARAM|cut -d'"' -f 12`
P_FILE_NAME=`echo $P_USER_PARAM|cut -d'"' -f 14`
P_FILE_DISP=`echo $P_USER_PARAM|cut -d'"' -f 16`
##Echoing user supplied params
echo "\nindivudal User Supplied Parameters"
echo "TO Mail Id:"$P_TO_ID
echo "CC Email Id:"$P_CC_ID
echo "Subject:"$P_SUBJECT
echo "Body1:"$P_BODY_1
echo "Body2:"$P_BODY_2
echo "File Attachment Path:"$P_FILE_PATH
echo "File Name:"$P_FILE_NAME
echo "File Display Name:"$P_FILE_DISP
P_BODY=$P_BODY_1$P_BODY_2
echo "\n Complete Body"
echo $P_BODY
## IF there is no file attachment
if [ -z "$P_FILE_PATH" ]
then
  echo "\nFile attachment not specified"
  ## IF there is no CC ID
  if [ -z "$P_CC_ID" ]
  then
     echo "\nCC Id is NULL"
     (echo $P_BODY) | mailx -s "${P_SUBJECT}" $P_TO_ID
  else
     echo "\nCC Id is NOT NULL"
     (echo $P_BODY) | mailx -s "${P_SUBJECT}" -c $P_CC_ID $P_TO_ID
  fi
fi
## If file attachment is present
if [ -n "$P_FILE_PATH" ]
then
  echo "\nFile attachment is specified"
  P_FILE_PATH=`echo $P_FILE_PATH|sed 's/\/$//'`
  echo "\nFile Path after removing trailing /"
  echo $P_FILE_PATH
  P_FILE_PATH=`eval echo $P_FILE_PATH`
  echo "\nFile Path after evaluating any Environment Variables"
  echo $P_FILE_PATH
  ## cd command is given only to check that the file path is a valid file path.
  ## If it is invalid, shell script will error out.
  cd $P_FILE_PATH
  P_FILE_ATTACH=$P_FILE_PATH/$P_FILE_NAME
  echo "\nComplete file path with attachment name"
  echo $P_FILE_ATTACH
  ## IF there is no CC ID
  if [ -z "$P_CC_ID" ]
  then
     echo "\nCC Id is NULL"
     ((echo $P_BODY);uuencode "${P_FILE_ATTACH}" "${P_FILE_DISP}") | mailx -s "${P_SUBJECT}" $P_TO_ID
  else
     echo "\nCC Id is NOT NULL"
     ((echo $P_BODY);uuencode "${P_FILE_ATTACH}" "${P_FILE_DISP}") | mailx -s "${P_SUBJECT}" -c $P_CC_ID $P_TO_ID
  fi
fi
if [ $? -eq 1 ]
then
    echo 'ERROR while sending email.  Please check log file'
    exit 1
fi
###### End of Shell Script ######

1 comment:

  1. what is the link between this code and the concurrent Program how can i call it ?

    ReplyDelete