Common Issue: Table to be displayed in mail content and not as an attachment

The requirement is to send a report from an UNIX server. I have a list of data to be shown on the report, say from database. I am using sendexchange to send mail and it always send in plain text fromat and the data displayed are not aligned properly. I have seperated all the columns with fixed width but even then I am not getting a proper alignment in the data :frowning:

Here it is

  1. I am using HP-UX
  2. I have only sendexchange, mailx and mail utilities to send mails
  3. I want to show the data not as an attachment but to be in the content of the mail.
  4. Mail Contents should be,
    [list=1]
  5. CONTENTS - Description of report
  6. TABLE
    [list=1]
  7. Header which will have column names
  8. Rows which holds the data
    [/list]

    [/list]

Any suggestions???

To make things line up, you'll need to ensure that the font used when reading your message is a fixed-width font. I don't know if you can specify what font will be used to read your message if you're not sending rich text or html. You could add a note at the start of your message saying that to see table data properly formatted, it must be viewed with a fixed width font (such as courier).

@Don: Thanks for the input!

Is there some way to change the format of the mail to "Text/html" or "rich text"???

I don't think you can just do it in the text of your message through mailx since you have to modify the message header to set the mime type of the contents. You could do it with sendmail. I've never worked with sendexchange, but the man page for it on your system may explain how to provide a mimetype of text/richtext or html for the messages you send through it.

Sorry,
Don

This is what I do to specify content type and email a HTML file in HP-UX using mailx

cat email_body.html | mailx -m -s "Email Subject 
Content-type: text/html" user@domain.com

Did you miss something there?? I expected that "Email Subject Content-type: text/html" would be on the subject line.

And that's what I got :frowning:

That is not correct. You have to put the Content-type: text/html in next line as I posted, this is to distinguish between email subject and mime header.

I did that.!! No use!

What do you mean by "No Use!". Tell us what exactly is the issue that you are facing?

For testing, try this code and see if you are getting a formatted email:

{
        echo "<html>"
        echo "<body>"
        echo "<table border=1 cellspacing=0 cellpadding=3>"
        echo "<tr>"
        echo "<td align=center><font face=verdana size=2 color=#FF0000>PikK45</font></td>"
        echo "</tr>"
        echo "</table>"
        echo "</body>"
        echo "</html>"
} | mailx -m -s "Test HTML
Content-type: text/html" user@domain.com

Put it in a file, change the recipient address and run it.

1 Like

Please show us exactly what you did do then, word for word, letter for letter, keystroke for keystroke, so that we won't suggest things you've already done again.

@Yoda, Corona688: Sorry that I did not give you enough details.

I tried Yoda's test script and it was successful. But when I tried last time, I guess I should have done some silly mistakes.

Anyway, Yoda saved me this time :slight_smile: :slight_smile:

Yes, you can do many neat things overloading the mailx -s / Subject: line into mime directives, like importance.

Hi PiKK, I have Recently worked on such an requirement. In this case u have to spool a file from the database using any colsep( set colsep ".") Then embed those data with html tags into an html file. Then need to send that html file as the content.

If things are not clear i can write a dummy code for you.

@Showdown: Thanks for your concern. That's what I did exactly :slight_smile:
@DGPickett: Is there any example of overloading that mailx's subject line??

Can you offer me examples or a link that has it?

If you see a toy in outlook or thunderbird that you want to duplicate, like importance, you can look at the message source when you receive it. If there are lines in the header area of the message near the Subject: line, you can put them in on unix/linux mail/mailx -s using a quoted line feed.

Received: from WLTWA305XUSE02.corp.bankofamerica.com
 ([fe80::b0f3:3f1b:bfbe:81e3]) by WLTWA301XUSE02.corp.bankofamerica.com
 ([fe80::586:ebe5:4135:ef7d%23]) with mapi id 14.02.0309.003; Wed, 20 Mar 2013
 14:56:59 -0400
Content-Type: application/ms-tnef; name="winmail.dat"
Content-Transfer-Encoding: binary
From: "my name" <my@email>
To: "my name" <my@email>
Subject: high importance, bank signature with graphic
Thread-Topic: high importance, bank signature with graphic
Thread-Index: Ac4lnLIsMUDJWyQMSBiGwrAktM9XKw==
Importance: high
X-Priority: 1
Date: Wed, 20 Mar 2013 14:56:58 -0400
Message-ID: <E2CF64EDAFC2A34F9CD656DDE4CF77CAD28817@WLTWA305XUSE02.corp.bankofamerica.com>
Accept-Language: en-US
Content-Language: en-US
X-MS-Has-Attach: yes
X-MS-Exchange-Organization-SCL: -1
X-MS-TNEF-Correlator: <E2CF64EDAFC2A34F9CD656DDE4CF77CAD28817@WLTWA305XUSE02.corp.bankofamerica.com>
MIME-Version: 1.0
X-MS-Exchange-Organization-AuthSource: WLTWA301XUSE02.corp.bankofamerica.com
X-MS-Exchange-Organization-AuthAs: Internal
X-MS-Exchange-Organization-AuthMechanism: 03
X-Originating-IP: [171.206.3.27]
X-MS-Exchange-Organization-AVStamp-Mailbox: SMEXr^dE;979900;0;This mail has
 been scanned by Trend Micro ScanMail for Microsoft Exchange;

If you want to compose the entire email, such as to do a message and multiple attachments or html with graphics, you need a more advanced email client like mutt or take over the entire upper layer using sendmail or connecting to port 25 to talk SMTP or ESMTP. However, you can steal the how from fancier email clients, as it all has to go into text in the end. Some mime email clients do send binary in the clear, but they embed it in the text with text start and end marker strings. It saves the > 4 for 3 cost of base 64 and uucp encodings.