Hi all,
I have written a shell script which sends emails with attachments to our clients. All our attachments are simple flat files (.txt format).
The script is working fine and sending the attachments to the mail-ids except that, when i am sending the attachments to non-outlook users (Like yahoo, gmail etc), i am seeing a junk character at the end of each line and the next line of file is appended to the previous line. In short all the data in the file is coming in one long line.
Here also there is a small twist. In gmail, there will be 2 options 2 download the file, View and Download. I am getting this problem only when i am downloading to the file to my local folder and viewing it.
Also when i am opening the same attachments in outlook, i can see that the data is appearing line by line as we entered it.
Kindly advise me, why this problem is occuring only when i am sending the mail to yahoo and gmail accounts. I am pasting the relavent code from my script.
*********************************************************
(
cat <<!
From: $FROM
Subject: $SUBJ
To: $TO
!
[ "$CC" ] && echo "Cc: $CC"
## Generate the MIME header #####
cat <<!
Mime-Version: 1.0
Content-Type: multipart/mixed; boundary="DMW.Boundary.605592468"
This is a Mime message, which your mail reader may not understand. Parts
of the message will appear as text. If the remainder appears as random
characters in the message body, instead of as attachments, then you'll
have to extract these parts and decode them manually.
--DMW.Boundary.605592468
Content-Type: text/plain; name="message.txt"; charset=US-ASCII
Content-Disposition: inline; filename="message.txt"
Content-Transfer-Encoding: 7bit
!
# Read the standard input as the main text of the message ...
# -------------------------------------------------------
cat -
# Now process the File attachments ...
# -----------------------------------------
if [ "$FILES" ]
then
for fl in $FILES
do
BASE=\`basename $fl\`
echo --DMW.Boundary.605592468
echo Content-Type: application/octet-stream\\; name=\\"$BASE\\"
echo Content-Disposition: attachment\\; filename=\\"$BASE\\"
echo Content-Transfer-Encoding: 7bit
echo
cat $fl
done
fi
# append the final boundary line ...
echo --DMW.Boundary.605592468--
) | /usr/lib/sendmail -t
*********************************************************
Thanks & Regards
Vamsi.