HTML table in email body using C Shell


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting HTML table in email body using C Shell
# 1  
Old 04-29-2015
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
Code:
mail -m "MIME-Version: 1.0;Content-type:text/html;charset=UTF-8" receiver@mail.com < file.html

#2
Code:
mail -m "Content-type: text/html;" -s "This is a test" receiver@mail.com < file.html

#3
Code:
test | sendmail -t

test file content:
Code:
 
 echo "From: sender@mail.com"
echo "To: receiver@mail.com"
echo "MIME Version: 1.0"
echo "Subject: Test"
echo "Content Type: text/html"
cat file.html

file.html:
Code:
 
 <!DOCTYPE html>
<html>
<table id="t01">
  <tr>
    <th>First Name</th>
    <th>Last Name</th>
    <th>Points</th>
  </tr>
  <tr>
    <td>Jill</td>
    <td>Smith</td>
    <td>50</td>
  </tr>
  <tr>
    <td>Eve</td>
    <td>Jackson</td>
    <td>94</td>
  </tr>
  <tr>
    <td>John</td>
    <td>Doe</td>
    <td>80</td>
  </tr>
</table>
</html>

I need following output in email body;
First Name Last Name Points
Jill Smith 50
Eve Jackson 94
John Doe 80

but receiving file.html content in the body of email.

I am getting required result if I send HTML code (file.html) in attachment but I need the HTML code result in email body.

Thanks!
# 2  
Old 04-30-2015
It's not clear what you mean. Are you trying to receive html formatted mail in your mail client? What is your mail client? When you say, you get "required result" if you send as an attachment, does this mean that when you click on the attachment it opens it up in a browser?

Also, never name a script test since this is a shell builtin.
Code:
test Command

Purpose

       Evaluates conditional expressions.

---------- Post updated at 12:07 ---------- Previous update was at 11:50 ----------

This works...

Code:
[josephgr@truth2 josephgr] cat foo.sh
cat <<EOD
From:  justadude@foo.bar.com
To: another.dude@someplace.com 
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Type: text/html; charset="UTF-8"
 <!DOCTYPE html>
<html>
<table id="t01">
  <tr>
    <th>First Name</th>
    <th>Last Name</th>
    <th>Points</th>
  </tr>
  <tr>
    <td>Jill</td>
    <td>Smith</td>
    <td>50</td>
  </tr>
  <tr>
    <td>Eve</td>
    <td>Jackson</td>
    <td>94</td>
  </tr>
  <tr>
    <td>John</td>
    <td>Doe</td>
    <td>80</td>
  </tr>
</table>
</html>
EOD

---------- Post updated at 12:08 ---------- Previous update was at 12:07 ----------

This works

./foo.sh | sendmail -t

Code:
[josephgr@truth2 josephgr] cat foo.sh
cat <<EOD
From:  justadude@foo.bar.com
To: another.dude@someplace.com 
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Type: text/html; charset="UTF-8"
 <!DOCTYPE html>
<html>
<table id="t01">
  <tr>
    <th>First Name</th>
    <th>Last Name</th>
    <th>Points</th>
  </tr>
  <tr>
    <td>Jill</td>
    <td>Smith</td>
    <td>50</td>
  </tr>
  <tr>
    <td>Eve</td>
    <td>Jackson</td>
    <td>94</td>
  </tr>
  <tr>
    <td>John</td>
    <td>Doe</td>
    <td>80</td>
  </tr>
</table>
</html>
EOD


Last edited by blackrageous; 04-30-2015 at 01:56 PM..
# 3  
Old 05-01-2015
Yes, I received the "required result" when I send as an attachment and click on the attachment it opens it up in a browser. I need the same result in the body of my mail client. I am using MS Outlook 2013 version.
# 4  
Old 05-01-2015
What do you get when you put HTML in the email body?
# 5  
Old 05-01-2015
I believe the content-type would be required to go after subject.

edit: I mean in regards to #3 being out of order.

Or perhaps like this:

Code:
mail -s 'Test
Content-Type: text/html' user@host.com < file.html

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Not able to generate table in email body

Below is the code snippet and I'm not able to generate the table in email, output email has nothing if ; then echo "File $fName exists." awk -F "," ' BEGIN { print "MIME-Version: 1.0" print "Content-Type: text/html" print "Subject: Out OF Network Fee - Portfolio Level Stats" print... (1 Reply)
Discussion started by: vyomdev
1 Replies

2. Shell Programming and Scripting

Postgre Query results as Email HTML table

Hello, I'm trying to send email from Greenplum query results as HTML table with status Red/Green Select Server, Last_Date from Table; Results Server, Last_Date Prod, 2018-04-09 Final email Output in HTML format Server Status LastDate Prod GREEN(BOX) 2018-04-09 (if... (2 Replies)
Discussion started by: krux_rap
2 Replies

3. 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

4. UNIX for Dummies Questions & Answers

Convert Txt file to HTML table and email

Hi all I need help converting a text file into a html table in bash and I need to email this table. The text file looks like the below. Two columns with multiple rows. Top row being header. Application Name Application Status Application 1 Open Application 2 ... (2 Replies)
Discussion started by: hitmanjd
2 Replies

5. Shell Programming and Scripting

Shell scripting unable to send the sql query data in table in body of email

I have written a shell script that calls below sql file. It is not sending the query data in table in the body of email. spool table_update.html; SELECT * FROM PROCESS_LOG_STATS where process = 'ActivateSubscription'; spool off; exit; Please use code tags next time for your code and data.... (9 Replies)
Discussion started by: Sharanakumar
9 Replies

6. Shell Programming and Scripting

SQL query output convert to HTML & send as email body

Hi , I have a sql query in the unix script ,whose output is shown below.I want to convert this output to HTML table format & send email from unix with this table as email body. p_id src_system amount 1 A 100 2 B 200 3 C ... (3 Replies)
Discussion started by: jagadeeshn04
3 Replies

7. Shell Programming and Scripting

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 : #!/usr/bin/ksh export MAILTO="email@domain.com" export SUBJECT="Report" export BODY="file_directory_path/test_file.txt"... (1 Reply)
Discussion started by: rockygsd
1 Replies

8. UNIX for Advanced & Expert Users

Mutt for html body and multiple html & pdf attachments

Hi all: Been racking my brain on this for the last couple of days and what has been most frustrating is that this is the last piece I need to complete a project. There are numerous posts discussing mutt in this forum and others but I have been unable to find similar issues. Running with... (1 Reply)
Discussion started by: raggmopp
1 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

Referring to attached images in html email body through mailx

encoding type for images? (5 Replies)
Discussion started by: biswasbaishali
5 Replies
Login or Register to Ask a Question