0

This is my HTML file below which draws a graph. When I am opening my HTML file using IE/Firefox/Chrome, I can see my graph properly.

I need to send this graph within an email body. When I try to use the below command, I can only see the plain text version of this HTML:

mail -r techgeeky@domain.com < graph.html

So I modified my file, graph.html like below by adding few lines at the top. And then again when I fire the above command, I am getting nothing in my mail body. Is there anything I need to add specifically at the top of the email to make this work? I am running SunOS 5.10.

From: techgeeky@domain.com
To: techgeeky@domain.com
Subject: MIME Test
Mime-Version: 1.0
Content-type: text/html; charset=utf-8
Content-transfer-encoding: us-ascii

<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', 100-16.81336174073654],
             ['Error Percentage', 16.81336174073654]
        ]);

        // 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>
Michael Petrotta
  • 59,888
  • 27
  • 145
  • 179
arsenal
  • 23,366
  • 85
  • 225
  • 331
  • 1
    You can't inject javascript into the body of an email. And for good reason! – Shmiddty Aug 22 '12 at 22:49
  • So is there any other way? because this javascript is drawing some graph, so can we capture thing thing in an image? and then pass this image into the body of an email? – arsenal Aug 22 '12 at 22:52

1 Answers1

0

You would have to:

  1. Grab the HTML generated with the javascript library
  2. Strip out any scripting, events, etc.
  3. Send the HTML string to your server (you may need to encode it)
  4. Send the email with the HTML string as its body from your server.
Shmiddty
  • 13,847
  • 1
  • 35
  • 52