Mail not properly shown in some email clients

Hi guys,

I've an issue with my mail send using shell script. My mail contain a HTML content/body and an attachment.

The mail content is shown in my Gmail account BUT in Yahoo and Outlook the content is missing.

Both Gmail and Outlook have attachment BUT in Yahoo the attachment content is empty.

When I send the HTML content only, all three mail HTML content are properly shown. Same goes to the attachment.

I've disabled my antivirus in-case of it blocking the content.

I suspected it is because of the multipart content type but after modifying it a few times still got the issue.

Maybe you guys have an ideas of what seem to be the issue?

Below is my code:

#!/usr/bin/ksh

dir="/home/sysadmin/deletion_log"
configfile="$dir/config.csv"
mailconfig="$dir/mail.txt"

while read config
do
	row=$(echo $config |cut -c1)
	if [[ $row != "#" ]]; then
		cust=$(echo $config |cut -d , -f1)			#customer
		num=$(echo $config |cut -d , -f2 |sed 's/ //g')		#SLA duration
		product=$(echo $config |cut -d , -f3)			#product
		product1=$(echo $config |cut -d , -f3 |sed 's/ //g')                   
		ptype=$(echo $config |cut -d , -f4 |sed 's/ //g')	#product type
		fname=$(echo $config |cut -d , -f5 |sed 's/ //g')	#filename
		fcode=$(echo $config |cut -d , -f6 |sed 's/ //g')	#filecode
		pdate=$(date "+%Y%m%d" "-d -$num days")
		fdate=$(date "+%Y-%m-%d" "-d -$num days")
		rdate=$(date "+%Y-%m-%d")
		pname="${fname}_$product1"				#product filename
		html="/tmp/${pname}_Deletion.html"			#html directory (eg. /tmp/BIMB_STMT_CASA_Deletion.html)
		dir=$(echo $config |cut -d , -f7 |sed 's/ //g')		#directory
		tfile=$(find $dir/$pdate/$fcode -type f |wc -l)		#total files
		rptdir=$(echo $config |cut -d , -f8)			#report directory
		dt=$(date "+%Y-%m")
		report="${rptdir}/${pname}_Report_${dt}.txt"		#report (eg. /home/sysadmin/data_bimbb/report/BIMB_STMT_CASA_Report_yyyy-mm.txt)
		Attachment=$report
		rptline="------------------------------------------------------------------------------------------------------------------------------------------------------------"			

		for maildt in $(cat $mailconfig) #Get recipient(s) in mail.txt
		do
			name=$(echo $maildt |cut -d , -f1)
			ToMail=$(echo $maildt |cut -d , -f2)

			#Create HTML table header
			print "<html>"                                                          > $html
			print "<h4>Dear ${name},</h4>"                                          >> $html
			print "<br>The $cust $product Deletion report as below</br>"               	>> $html
			print "<p><b>SYSTEM NAME�������: 192.168.10.102</b></p>" >> $html
			print "<p><b>DIRECTORY NAME��: $dir/$pdate/</b></p>"                               >> $html
			print "<p><b>TOTAL FILES����������: $tfile</b></p>" >> $html
			print "<table border=\"1\">"                              >> $html
			print "<tr>"                                                            >> $html
			print "<td><div align=\"center\"><strong>File Name</strong></div></td>" >> $html
			print "<td><div align=\"center\"><strong>Sub Directory</strong></div></td>" >> $html
			print "<td><div align=\"center\"><strong>Received Date</strong></div></td>" >> $html
			print "<td><div align=\"center\"><strong>Remove Date</strong></div></td>" >> $html
			print "<td><div align=\"center\"><strong>Time Start</strong></div></td>"  >> $html
			print "<td><div align=\"center\"><strong>Time Finish</strong></div></td>" >> $html
			print "<td><div align=\"center\"><strong>Action Taken</strong></div></td>">> $html
			print "<td><div align=\"center\"><strong>Taken By</strong></div></td>"    >> $html
			print "</tr>"                                                             >> $html
			
			count=$(ls $report |wc -l)
			#Create report header
			if [[ $count -eq 0 ]]; then
				print $rptline >> $report
				printf "|%-5s|%-6s|%-14s|%-12s|%-70s|%-20s|%-10s|%-10s|\n" "Year" "Month" "Date Received" "Date Delete" "Folder" "File Name" "Name" "Signature"  >> $report
				print $rptline >> $report
			fi
			
			year=$(date "+%Y")
			month=$(date "+%m")
			
			count=`find $dir/$pdate/$fcode -type f |wc -l`
			if [[ $count -gt 0 ]]; then
				for list in `find $dir/$pdate/$fcode -type f | sort`
				do
					fname=$(echo $list |rev |cut -d \/ -f1 |rev)
					fdir=$(echo $list |rev |cut -d \/ -f2- |rev)
					tmp=$(echo $dir/$pdate/ |wc -c)
					subdir=$(echo $fdir |cut -c $tmp-)
					lname=$(echo $list |rev |cut -d \/ -f3- |rev)
					stime=$(date "+%H:%M:%S")
					ftime=$(date "+%H:%M:%S")
				
					#rm -f $lname
				
					printf "|%-5s|%-6s|%-14s|%-12s|%-70s|%-20s|%-10s|%-10s|\n" $year $month $fdate $rdate $fdir $fname "Sysadmin" "Auto" >> $report
					print $rptline >> $report
					print "<tr>" >> $html
				        print "<td ><div align=\"center\">$fname</div></td>" >> $html
				        print "<td ><div align=\"center\">$subdir</div></td>" >> $html
				        print "<td ><div align=\"center\">$fdate</div></td>" >> $html
				        print "<td ><div align=\"center\">$rdate</div></td>" >> $html
				        print "<td ><div align=\"center\">$stime</div></td>" >> $html
				        print "<td ><div align=\"center\">$ftime</div></td>" >> $html
				        print "<td ><div align=\"center\">"Remove File"</div></td>" >> $html
				        print "<td ><div align=\"center\">"Sysadmin"</div></td>"    >> $html
				        print "</tr>" >> $html
				
				done
			
				
				#rm -rf $dir/$pdate
				
				print "</table>"  >> $html
                                print "</html>"   >> $html				

				unix2dos $Attachment #Convert file to dos format

				#Send mail
				MAILPART=`uuidgen`
				MAILPART_BODY=`uuidgen`
				(
					echo "From: \"Someone\"<admin@someweb.com.my>"
					echo "To: \"${name}\"<$ToMail>"
					echo "Subject: [Notification] $cust $product Deletion Report"
					echo "MIME-Version: 1.0"
					echo "Content-Type: multipart/mixed; boundary=\"$MAILPART\""
					echo "--$MAILPART"
					echo "Content-Type: multipart/alternative; boundary=\"$MAILPART_BODY\""
					echo "--$MAILPART_BODY"
					echo "Content-Type: text/html; charset=UTF-8"
				        echo "Content-Disposition: inline"
					cat $html |tr -d '\r'
					echo "--$MAILPART_BODY--"
					echo "--$MAILPART"
					echo 'Content-Type: application/pdf; name="'$(basename $Attachment)'"'
				        echo "Content-Transfer-Encoding: uuencode"
				        echo 'Content-Disposition: attachment; filename="'$(basename $Attachment)'"'
				      	uuencode $Attachment $(basename $Attachment)
					echo "--$MAILPART--"
				) > /tmp/${pname}_Deletion_Report.html
				cat /tmp/${pname}_Deletion_Report.html | /usr/sbin/sendmail $ToMail
			fi
		done
	fi
done < $configfile

Any help would be greatly appreciated. Thank you.

--Muaz

Did you try to look at the mail source from within the clients? Sometimes contents is hidden - even though it's there - that is thought to be "binary".

Could be like how different browsers render html differently? If so, you may find it easier to write different html for the different mail clients. Then you could write a script that sends the specific html needed for the correct clients. This may be easier in the long run than trying to make it cross-platform.

In Outlook the content source is empty but it has the attachment - I right clicked and view source.

Does it means I have to write three different html for gmail, yahoo and outlook? How can I get the html format for each?

Thanks