title: shell script not sending mail accurately using SMTP server
body: <p>I wrote script to send mail automatically using an SMTP connection but when I execute the script, sometimes it works and sometimes it is not sending mail. Behavior is quite ambiguous.</p>
  
  <pre><code>Environment : Linux Server Fedora 14 
  Mailing Client : Lotus Notes 8.5.2
  </code></pre>
  
  <p>Please find script below.</p>
  
  <pre><code># Function for sending email
  sendemail(){
  date=`date '+%d-%m-%Y'`
  dbDir=/var/lib/MYSQLBACKUP/$date
  dbname='DBNAME'
  log_file="${dbDir}/${dbname}_${date}.log"
  attached_file="${dbname}_${date}.log"
  echo $log_file
  echo $attached_file
  encoded_log_file=`cat $log_file | openssl base64`
  #echo $encoded_log_file
  ( echo open 172.40.201.31 25
  sleep 8
  echo helo 172.40.201.31
  echo mail from:Pratik.Vyas@gmail.com
  echo rcpt to:Pratik.Vyas@gmail.com
  echo data
  echo to:Pratik.Vyas@gmail.com
  echo from:Pratik.Vyas@gmail.com
  echo "subject: SPARC CQ DB Backup Report : $date :"
  echo "MIME-Version: 1.0"
  #echo "Content-Type: text/plain; charset=UTF-8"
  #echo "Please view attached file"
  echo "Content-Type: text/x-log;name="$attached_file""
  echo "Content-Disposition:attachment;filename="$attached_file""
  echo "Content-Transfer-Encoding: base64"
  echo $encoded_log_file
  echo $1
  sleep 15
  echo .
  echo ^]
  echo quit ) | telnet
  echo "status:$?"
  echo "Hello done"
  }
  
  sendemail
  </code></pre>