如何在电子邮件中发送带有html表输出的电子邮件

时间:2013-04-10 06:54:28

标签: android debugging whitespace html-table html-email

我正在使用ArrayList,我想发送带有arraylist内容的html格式的电子邮件类型, 我正在尝试在BufferedWriter中编写数组内容..

mOrderList = db.getOrderList();
    // getting all arrayList content
     for (int i = 0; i < mOrderList.size(); i++) {
     no = mOrderList.get(i).getId();
     itemName = mOrderList.get(i).getOrderItemName();
     unit = mOrderList.get(i).getOrderUnit();
     qty = mOrderList.get(i).getOrderQTY();
     rate = mOrderList.get(i).getOrderRate();
     amt = mOrderList.get(i).getOrderAmount();
     try {
         mbufferWriter =new BufferedWriter(new FileWriter("/data/data/com.sample.category/abc.txt"));
     mbufferWriter.write("<html><h4>Customer Order List</h4>" + "<body> <table>"
                + "<tr><th>Item No</th>" + "<th>Item Name</th>"
                + "<th>Unit</th>" + "<th>QTY</th>" + "<th>Item Rate</th>"
                + "<th>Amount</th></tr>");
     mbufferWriter.append("<tr><td>" +no+"</td>");
     mbufferWriter.append("<td>"+itemName+ "<td>");
     mbufferWriter.append("<td>"+unit+ "<td>");
     mbufferWriter.append("<td>"+qty+ "<td>");
     mbufferWriter.append("<td>"+rate+ "<td>");
     mbufferWriter.append("<td>"+amt+ "<td></tr>");
     mbufferWriter.append("</body></table></html>");
     mbufferWriter.close();

     } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

     }//for

并尝试发送此类电子邮件,但却出错...

Intent i = new Intent(Intent.ACTION_SEND);
                i.setType("message/rfc822");
                i.putExtra(Intent.EXTRA_EMAIL,
                        new String[] { "abc@gmail.com" });
                i.putExtra(Intent.EXTRA_SUBJECT, "sample email sending");

                i.putExtra(Intent.EXTRA_TEXT,Html.toHtml((Spanned) mbufferWriter));

                try {
                    startActivity(Intent.createChooser(i, "Send mail..."));
                    // startActivity(i);
                } catch (android.content.ActivityNotFoundException ex) {
                    Toast.makeText(EmailActivity.this,
                            "There are no email clients installed.",
                            Toast.LENGTH_SHORT).show();
                }

任何人都可以帮我解决这个问题.. 提前谢谢..

2 个答案:

答案 0 :(得分:0)

Html.toHtml不支持<table>。它仅支持<b><u><i> ...

等基本标签

答案 1 :(得分:-1)

使用pre标记创建表格:

 mbufferWriter.write("<html><h4>Customer Order List</h4>" + "<body>" + 
        "<pre> " +
            "  Item No    Item Name    Unit     QTY   Item Rate     Amount" +
        "</pre>");