Monday 7 January 2013

Sending Mails using Sendmail with Subject and Attachment and Mail Body in Unix

Suppose you have a list of 10-15(or more) files to zip together and send to a mail. Take the filesnames to filelist.txt and all the mail addresses to listofmailids.txt file.

$ cat xxecms_sendmail_decrypt.sh
#!/bin/sh

while read FILE; do cp $FILE ZIP_HOLDER/ ; done < filelist.txt
ls -ltr ZIP_HOLDER/*; sleep 2
zip ZIP_HOLDER.zip ZIP_HOLDER/*
ls -ltr ZIP_HOLDER.zip; sleep 2

FILE="ZIP_HOLDER.zip"
echo "From:
malay.khawas@mailaddress.local" > "MESSAGE_FILE"
echo "To: `cat listofmailids.txt`" >> "MESSAGE_FILE"
echo "Subject: Mail Attachment - From ECMS System" >> "MESSAGE_FILE"
echo "Content-type: multipart/mixed >/dev/null"
echo "Please find all the files in a Zipped Folder" >> "MESSAGE_FILE"
echo "Please contact sysadmin team if you need any help" >> "MESSAGE_FILE"
uuencode ${FILE} ${FILE} >> MESSAGE_FILE
cat MESSAGE_FILE | /usr/sbin/sendmail -t

rm -f ZIP_HOLDER/*
rm -f ZIP_HOLDER.zip
$



Sendmail with Subject and Attachment

FILE="SCM.ldt"
echo "From:
malay.khawas@mailaddress.local" > "MESSAGE_FILE"
echo "To:
malay.khawas@mailaddress.local" >> "MESSAGE_FILE"
echo "Subject: Report for Testing Bangladesh" >> "MESSAGE_FILE"
echo "Content-type: multipart/mixed >/dev/null"
echo "Hello How Are you" >> "MESSAGE_FILE"
echo "I have sent this as test mail" >> "MESSAGE_FILE"
uuencode ${FILE} ${FILE} >> MESSAGE_FILE
cat MESSAGE_FILE | /usr/sbin/sendmail -t

No comments:

Post a Comment