Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Problem Statement:-

Currently I am sending an email using mailx by attaching an html file within the email. But I want to send an email using mailx command instead of attaching the html file in an email, I want to show the results of html file within an email body.

Below is the script I am using to send an email with some content in the body of an email and attaching chart.html file in an email. And instead of attaching html file in an email, I want to show the output of html file within an email body. Can anyone show me an example basis on my below script what changes I need to make to accomplish this?

mailx -s "LIP for $DATE_YEST_FORMAT1" -r techgeeky@host.com techgeeky@host.com <<EOF

Total Items Purchased: `echo $QUERY1 | awk '{print $1}'`

Total Items Missingo: `echo $QUERY1 | awk '{print $2}'`

Error Percentage: $QUERY2

`uuencode /tmp/chart.html chart.html`

EOF

And this is my chart.html file which draws a graph- So I need to show this graph within the email body.

<html>
  <head>
    <!--Load the AJAX API-->
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">

      // Load the Visualization API and the piechart package.
      google.load('visualization', '1.0', {'packages':['corechart']});

      // Set a callback to run when the Google Visualization API is loaded.
      google.setOnLoadCallback(drawChart);

      // Callback that creates and populates a data table,
      // instantiates the pie chart, passes in the data and
      // draws it.
      function drawChart() {

        // Create the data table.
        var data = new google.visualization.DataTable();
        data.addColumn('string', 'Title');
        data.addColumn('number', 'Value');
        data.addRows([
          ['No Error Percentage', $NOERROR],
             ['Error Percentage', $ERROR]
        ]);

        // Set chart options
        var options = {'title':'LIP Data Quality Report',
                       'width':700,
                       'height':600};

        // Instantiate and draw our chart, passing in some options.
        var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
        chart.draw(data, options);
      }
    </script>
  </head>

  <body>
    <!--Div that will hold the pie chart-->
    <div id="chart_div" style="width:900px; height: 800px;"></div>
  </body>
</html>

Any help will be appreciated. And I am running SunOS

bash-3.00$ uname -a
SunOS lvsaishdc3in0001 5.10 Generic_142901-02 i86pc i386 i86pc
share|improve this question

1 Answer 1

up vote 3 down vote accepted

You cannot do that with text/plain email. To directly embed that html into the email message will only work if the receiving email client software supports JavaScript. I am not aware of any that do.

You basically have two options. The first is to have graphing software produce an image file that can be embedded in an HTML email. This image will be presented in the email at the location it is embedded. The second is to include a link in an HTML email that will present the graph. This will probably require a browser to be opened to get the actual content.

With the first option, you would have to build the email message using Content-Type: multipart/related type="multipart/alternative", including at least two parts, the first of type text/html and the second of type image/<whatevertypeyourimageis>. See the "Including Images" section on this page for more information on how to do it.

With the second option, there are two different approaches. The first is to put up a generic page that accepts data encoded in the URL and renders the page accordingly. The second is to put up a unique page for each data set.

share|improve this answer
    
@Renan, thanks for the formatting update. –  Yedric Sep 17 '12 at 13:28

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.