Mail not properly shown in some email clients | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Mail not properly shown in some email clients

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 02-08-2013
muazrs muazrs is offline
Registered User
 
Join Date: Feb 2013
Last Activity: 24 February 2013, 8:41 PM EST
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Code 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:

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&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: 192.168.10.102</b></p>" >> $html
			print "<p><b>DIRECTORY NAME&nbsp;&nbsp;: $dir/$pdate/</b></p>"                               >> $html
			print "<p><b>TOTAL FILES&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: $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
Sponsored Links
    #2  
Old 02-09-2013
RudiC RudiC is offline Forum Advisor  
Registered User
 
Join Date: Jul 2012
Last Activity: 25 October 2014, 1:16 PM EDT
Location: Aachen, Germany
Posts: 4,427
Thanks: 73
Thanked 1,084 Times in 1,022 Posts
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".
Sponsored Links
    #3  
Old 02-09-2013
Azrael's Avatar
Azrael Azrael is offline
Registered User
 
Join Date: Sep 2011
Last Activity: 24 October 2014, 12:29 AM EDT
Posts: 95
Thanks: 32
Thanked 3 Times in 3 Posts
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.
    #4  
Old 02-09-2013
muazrs muazrs is offline
Registered User
 
Join Date: Feb 2013
Last Activity: 24 February 2013, 8:41 PM EST
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by RudiC View Post
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".
In Outlook the content source is empty but it has the attachment - I right clicked and view source.

Quote:
Originally Posted by Azrael View Post
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.
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
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Send email using mail il_labor Red Hat 1 01-05-2012 02:00 AM
Send email using mail il_labor Linux 1 01-04-2012 06:18 PM
Shell Script Email not working Properly karthikraj Shell Programming and Scripting 9 10-14-2009 12:54 AM
sending email via mail server parmeet UNIX for Advanced & Expert Users 1 02-09-2007 01:39 AM



All times are GMT -4. The time now is 03:43 AM.