Email body not formatted with html and sendmail


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Email body not formatted with html and sendmail
# 1  
Old 12-31-2013
Email body not formatted with html and sendmail

Hi All,

I am trying to send the contents of a file as email body. I am using html email and sendmail option of unix. I am using the below piece of code for the same :

Code:
#!/usr/bin/ksh
export MAILTO="email@domain.com"
export SUBJECT="Report"
export BODY="file_directory_path/test_file.txt"
export ATTACH="file_directory_path/test_file.txt"
(
 echo "To: $MAILTO"
 echo "Subject: $SUBJECT"
 echo "MIME-Version: 1.0"
 echo 'Content-Type: multipart/mixed; boundary="-q1w2e3r4t5"'
 echo
 echo '---q1w2e3r4t5'
 echo "Content-Type: text/html"
 echo "Content-Disposition: inline"
 cat $BODY | column -t -s ","
 echo '---q1w2e3r4t5'
 echo 'Content-Type: application; name="'$(basename $ATTACH)'"'
 echo "Content-Transfer-Encoding: base64"
 echo 'Content-Disposition: attachment; filename="'$(basename $ATTACH)'"'
 uuencode --base64 $ATTACH $(basename $ATTACH)
 echo '---q1w2e3r4t5--'
) | /usr/sbin/sendmail $MAILTO

But the output i am getting is :

Code:
"ABCD ASDFG" "N" "QWER" "" "90361" "AZ QWERTYU QWERTYUI" "E" "QWER" "20131021" "9" "AZ QWERTYU QWERTYUI" "E" "ASDF" "20131024" "9"

The output i require is :

Code:
"ABCD ASDFG"                  "N"  "QWER"  ""               "90361" 
"AZ QWERTYU QWERTYUI"  "E"  "QWER"  "20131021"  "9" 
"AZ QWERTYU QWERTYUI"  "E"  "ASDF"   "20131024"  "9"

The file_test.txt looks like:
Code:
"ABCD ASDFG","N","QWER","","90361"
"AZ QWERTYU QWERTYUI","E","QWER","20131021","9"
"AZ QWERTYU QWERTYUI","E","ASDF","20131024","9"

Please help me in formatting the email body !

Last edited by rockygsd; 12-31-2013 at 01:16 AM.. Reason: Data protect
# 2  
Old 12-31-2013
The file "test_file.txt" is not html formatted so you need to append each line with a "<br>" on creation or editting it when it is streamed to sendmail - something like:

Code:
column -t -s "," ${BODY} | sed 's/$/<br\>/'

---------- Post updated at 09:41 AM ---------- Previous update was at 09:11 AM ----------

forgot you'll need to start the message body with paragraph tags so this is what you wind up with:

Code:
(
 echo "To: $MAILTO"
 echo "Subject: $SUBJECT"
 echo "MIME-Version: 1.0"
 echo 'Content-Type: multipart/mixed; boundary="-q1w2e3r4t5"'
 echo
 echo '---q1w2e3r4t5'
 echo "Content-Type: text/html"
 echo "Content-Disposition: inline"
 echo "<p>"
 column -t -s "," ${BODY} | sed 's/$/<br\>/'
 echo "</p>"
 echo '---q1w2e3r4t5'
 echo 'Content-Type: application; name="'$(basename $ATTACH)'"'
 echo "Content-Transfer-Encoding: base64"
 echo 'Content-Disposition: attachment; filename="'$(basename $ATTACH)'"'
 uuencode --base64 $ATTACH $(basename $ATTACH)
 echo '---q1w2e3r4t5--'
) | /usr/sbin/sendmail $MAILTO

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Regarding guidance related to HTML table in email body

Hello All, I have a query here. I am sending an HTML table(which I am creating it by a call to REST API, in a LINUX box) and from there I have to send it into an email. So following are the poins on same: As data is not static so it is writing Dynamic data and creating HTML file. There is... (9 Replies)
Discussion started by: RavinderSingh13
9 Replies

2. Shell Programming and Scripting

Sendmail cmd for html body and attachment not working

Hi, I am having trouble in sending a mail with html body and attachment (csv file). We don't have uuencode or mutt (not allowed to install as well) The below code is perfectly working for sending the html body alone: export MAILTO=abc@xyz.com export CONTENT="/home/abc/list.html"... (2 Replies)
Discussion started by: close2jay
2 Replies

3. Shell Programming and Scripting

HTML table in email body using C Shell

I am using Sun Solaris ver. 5.10 and trying to send an HTML table in email body using mail command in C shell script. I tried following commands:- #1 mail -m "MIME-Version: 1.0;Content-type:text/html;charset=UTF-8" receiver@mail.com < file.html #2 mail -m "Content-type: text/html;" -s "This... (4 Replies)
Discussion started by: jnrohit2k
4 Replies

4. UNIX for Dummies Questions & Answers

Sendmail with HTML body and attachment code issues

Hi, I was working on getting an HTML file in the mail body along with attaching a "csv" file to the mail. Below are the 2 parts of the code. I need help with the second part where I'm sending the mail. The HTML file as an attachment is perfect without any issues and with proper formatting.... (6 Replies)
Discussion started by: aster007
6 Replies

5. Shell Programming and Scripting

Sending formatted email with sendmail question

Hi All, Can anyone help with an email formatting question: Im using the following example to try and send a formatted email: outputFile="file.txt" ( echo "From: oracle@inovis.com" echo "To: john.dickinson@gxs.com" echo "MIME-Version: 1.0" echo "Subject: Test Font" echo... (4 Replies)
Discussion started by: jonnyd
4 Replies

6. UNIX for Dummies Questions & Answers

Sendmail with cat adding extra spaces in email body

when I try to read a file and send email using cat and sendmail: The email received having additional spaces.(Between the letters of words in the text) My code: export MAILTO="sa@y.com" export SUBJECT="mydomain PREPROD MONITOR AT ${DATE}" export... (5 Replies)
Discussion started by: visitsany
5 Replies

7. Shell Programming and Scripting

Sendmail with header and footer logo in HTML body

Hello, I need help with my script that will send email via sendmail command that will shows both the header and footer logo once the recepient receive the email (e.g. MS Outlook). When I tested to ran the script it will successfully send the email BUT UNFORTUNATELY it doesn't displayed the... (8 Replies)
Discussion started by: lawrence88
8 Replies

8. Shell Programming and Scripting

Sendmail with HTML body and attachment

I have an HTML file I am currently sending in the body of an email. I now have a need to send a csv attachment along with it. I can ONLY use sendmail as mutt and xmail etc are not on the server. Here is what I am currently using: It is possible to add code to add an attachment ??!? { ... (8 Replies)
Discussion started by: atelford
8 Replies

9. UNIX for Advanced & Expert Users

Email with multiple attachments & HTML body

I have a html file: # cat sample.html <html> <body> Sample HTML file</p> </body> </html> And I have two excel sheets (sheet1.xls & sheet2.xls) I want to send an email by having the sample.html as the message body and two spreadsheets as the attachments. I tried using the below command:... (12 Replies)
Discussion started by: BHM
12 Replies

10. Shell Programming and Scripting

Sendmail with html attachment and html body

Hi folks, I have a perl script which sends out email after successful completion of job as inline html, I want to send it out as two parts now as html inline and html attachment. see the attached script. Thanks in advance (1 Reply)
Discussion started by: sol_nov
1 Replies
Login or Register to Ask a Question