使用Apache Commons Email在HTML电子邮件中绘制饼图

时间:2016-08-19 07:13:25

标签: java email html-email apache-commons

我想向我的客户发送统计信息,显示每个终端或分支上处理的交易数量。我正在使用Apache Commons Email发送HTML电子邮件。 我想在网站上发送一个像this一样的饼图数据。 我的java代码是基本提取的from

就像:

public void testHtmlEmailPiechart() 
            throws UnsupportedEncodingException, EmailException, MalformedURLException { 
        HtmlEmail email = new HtmlEmail(); 
        email.setHostName(emailServer); 
        email.setSmtpPort(587); 
        email.setSSLOnConnect(true); 
        email.setAuthentication(userName, password); 
        email.setCharset(emailEncoding); 

        email.addTo(receiver, "Mwesigye John Bosco"); 
        email.setFrom(userName, "Enovate system emailing alert"); 
        email.setSubject("Conkev aml Engine Statistics"); 

        URL url = new URL("https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcROXe8tn1ljtctM53TkLJhLs6gEX56CvL0shvyq1V6wg7tXUDH8KRyVP30"); 
//        URL url = new URL("http://www.apache.org/images/asf_logo_wide.gif"); 
        String cid2 = email.embed(url, "logo.gif"); 

        email.setHtmlMsg("<html>\n" +
"  <head>\n" +
"    <script type=\"text/javascript\" src=\"https://www.gstatic.com/charts/loader.js\"></script>\n" +
"    <script type=\"text/javascript\">\n" +
"      google.charts.load(\"current\", {packages:[\"corechart\"]});\n" +
"      google.charts.setOnLoadCallback(drawChart);\n" +
"      function drawChart() {\n" +
"        var data = google.visualization.arrayToDataTable([\n" +
"          ['Task', 'Hours per Day'],\n" +
"          ['Work',     11],\n" +
"          ['Eat',      2],\n" +
"          ['Commute',  2],\n" +
"          ['Watch TV', 2],\n" +
"          ['Sleep',    7]\n" +
"        ]);\n" +
"\n" +
"        var options = {\n" +
"          title: 'My Daily Activities',\n" +
"          is3D: true,\n" +
"        };\n" +
"\n" +
"        var chart = new google.visualization.PieChart(document.getElementById('piechart_3d'));\n" +
"        chart.draw(data, options);\n" +
"      }\n" +
"    </script>\n" +
"  </head>\n" +
"  <body>\n" +
"    <div id=\"piechart_3d\" style=\"width: 900px; height: 500px;\">Piechart Data</div>\n" +
"  </body>\n" +
"</html>"); 
        email.setTextMsg("Your email client does not support HTML messages"); 

        email.send(); 
    }  

我的猜测是JavaScript无法识别,因为代码的作用类似于发送图像,样式字体以及我已经发送到我的电子邮件地址的一些示例邮件。只要我正在使用Java,我希望您能帮助或推荐我可以阅读的任何材料。这些流程在后台自动运行,因此不涉及用户界面。 感谢。

0 个答案:

没有答案