#!/bin/bash
#usage: $0 <smtp server> <mail from> <mail to>
# It reads from standar input and sends this info to
# a given email address.
# Do not forget to set MAIL FROM, Subject, and from domain

smpt=$1
mail_to=$2

# script internal parameters
mail_from="newton@usm.cl"
mySubject="Files update report"
from_domain="fis.utfsm.cl"

Mail_data()
{
echo "HELO $from_domain"
echo "MAIL FROM: $mail_from"
echo "RCPT TO: $1"
echo "DATA"
echo "Subject:$mySubject"
echo "From: $mail_from"
echo "To: $1"
while read line
do 
   echo $line
done
# to make sure there is a . in the last line
echo "."   
}

Mail_data $mail_to | telnet $smpt 25  >> /dev/null