Mail not properly shown in some email clients


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Mail not properly shown in some email clients
# 1  
Old 02-09-2013
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
# 2  
Old 02-09-2013
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".
# 3  
Old 02-09-2013
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
Quote:
Originally Posted by RudiC
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
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
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Use of java mail to send email from UNIX

Can someone help me to understand how to configure java mail on unix or what is syntex for that to put in script so email can be sent. earlier i was using 'send mail' to send email and not SMPT is stopped in unix machine and they asked us to use java mail. Before I was using this ... (0 Replies)
Discussion started by: mirwasim
0 Replies

2. Shell Programming and Scripting

unix email attachments in web mail

Hi, Request you to please help on my issue. My issue is: We are able to send the log files as an email attachment. We are able to get the attachment in our inbox. But when we try to see in web mail, instead of the attachment, junk characters are displaying. Appreciate your help. Regards,... (10 Replies)
Discussion started by: gi.srinivas
10 Replies

3. Red Hat

Send email using mail

I need to send an email from linux using mail command. The problem is I can't hardcode the to: emailaddress, The email address is saved in a recipient.lst file on the server in this format: To: a@b.com Thanks a lot. il_labor (1 Reply)
Discussion started by: il_labor
1 Replies

4. Linux

Send email using mail

I need to send an email from linux using mail command. The problem is I can't hardcode the to: emailaddress, The email address is saved in a recipient.lst file on the server in this format: To: a@b.com Thanks a lot. il_labor (1 Reply)
Discussion started by: il_labor
1 Replies

5. Shell Programming and Scripting

Script to Send an email using mail command

Hello all I'm trying to write a script to send an email, so I can be nnotified when something is going wrong with my system. I've tried many options with no luck: mail -s "You've got mail" somebody@example.com echo "Mail Body" | mail -s "Subject" somebody@example.com I tried also to... (1 Reply)
Discussion started by: samer.odeh
1 Replies

6. Shell Programming and Scripting

Shell Script Email not working Properly

Hi GURU's, I'm using a Shell Script to send email's as an attachment. I'm Storing the email address in a table and catching in a variable. MAILLIST=`noarg sqlplus -s $OraUsr << EOF set heading off set feedback off set echo off SELECT email_ids FROM tpemail_table WHERE... (9 Replies)
Discussion started by: karthikraj
9 Replies

7. Shell Programming and Scripting

how to know if the mailx command really sends the mail to the email address?

Hi guys, I have a question about the returning message of the mailx command. if I run a mailx command, how can I know if the email has been sent to the email address? If the email address doesn't exist, is there any error message returned? If yes, how can I get the error message? Thanks... (3 Replies)
Discussion started by: sheenshine
3 Replies

8. UNIX for Advanced & Expert Users

sending email via mail server

hi everyone i am facing one problem. there is one unix server in our organisation which stores daily routine backup, and one mail server which is on windows 2k3, they are on one intranet. now i want that a mail should be generated and sent to the e-mail id of employees like nitin@hotmail.com... (1 Reply)
Discussion started by: parmeet
1 Replies

9. UNIX for Dummies Questions & Answers

how to send mail from server to client's email-id

i want to send email from server to the client's email-id. server is solaris. please help me out.i want to send mail to the email-id not to the var/spool/mail. (8 Replies)
Discussion started by: parmeet
8 Replies
Login or Register to Ask a Question