0

我必须开发一个 android 示例。

使用 javamail api 从我的 android 应用程序发送多个项目详细信息到邮件。

在这里我必须运行该应用程序意味着仅将最新添加的产品发送到邮件。但我必须将所有添加的产品详细信息发送到电子邮件。我该怎么办。请帮助我。我的代码有什么问题。请检查代码并为我提供解决方案。

我使用了以下代码:

 public class InvoiceOrder extends Activity {


String mGrandTotal;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub  
    super.onCreate(savedInstanceState);
    setContentView(R.layout.invoice);
    ListView mLstView1 = (ListView) findViewById(R.id.listView1);


    CustomerAdapter mViewCartAdpt = new CustomerAdapter(
            InvoiceOrder.this);
    mLstView1.setAdapter(mViewCartAdpt);

            Button login = (Button) findViewById(R.id.mBtnSubmit);
            login.setOnClickListener(new View.OnClickListener() {

        public void onClick(View arg0) {
            Properties props = new Properties();
            props.put("mail.smtp.host", "smtp.gmail.com");
            props.put("mail.smtp.socketFactory.port", "465");
            props.put("mail.smtp.socketFactory.class",
                    "javax.net.ssl.SSLSocketFactory");
            props.put("mail.smtp.auth", "true");
            props.put("mail.smtp.port", "465");

            Session session = Session.getDefaultInstance(props,
                new javax.mail.Authenticator() {
                    protected PasswordAuthentication getPasswordAuthentication() {
                        return new PasswordAuthentication("krishnaveniv96@gmail.com","xxxxxx");
                    }
                });

            try {

                Message message = new MimeMessage(session);
                message.setFrom(new InternetAddress("krishnaveni.veeman@gmail.com"));
                message.setRecipients(Message.RecipientType.TO,
                        InternetAddress.parse("mercy.krishnaveni@gmail.com"));
                message.setSubject("Testing Subject");
                StringBuilder sb = new StringBuilder();                  
              //  message.setContent("This is your product name : "+
                    //    "Hi Krishna" +"<br></br>This is your price : "+ "Hi veni", "text/html; charset=utf-8");
                for (int i = 0; i < Constants.mItem_Detail
                        .size(); i++) {

                    String title = Constants.mItem_Detail
                            .get(i).get(
                                    SingleMenuItem.KEY_PNAME);

                    String qty = Constants.mItem_Detail.get(i)
                            .get(SingleMenuItem.KEY_QTY);

                    String cost = Constants.mItem_Detail.get(i)
                            .get(SingleMenuItem.KEY_PRICE);

                    String total = Constants.mItem_Detail
                            .get(i).get(
                                    SingleMenuItem.KEY_TOTAL);

                message.setContent("<tr>" + "<td>" + title
                            + "</td><td>" + qty + " * " + cost
                            + "</td>" + " = <td>" + total
                            + "  " + "</td></tr>", "text/html; charset=utf-8"); 

                }

                Transport.send(message);

                System.out.println("Done");

            } catch (MessagingException e) {
                throw new RuntimeException(e);
            }
           }



  });

编辑

                try {

                Message message = new MimeMessage(session);
                message.setFrom(new InternetAddress("krishnaveni.veeman@mercuryminds.com"));
                message.setRecipients(Message.RecipientType.TO,
                        InternetAddress.parse("mercy.krishnaveni@gmail.com"));
                message.setSubject("Testing Subject");
                //StringBuilder sb = new StringBuilder();     
                StringBuilder body = new StringBuilder();

                body.append("<html><body><table>");


              //  message.setContent("This is your product name : "+
                    //    "Hi Krishna" +"<br></br>This is your price : "+ "Hi veni", "text/html; charset=utf-8");
                for (int i = 0; i < Constants.mItem_Detail
                        .size(); i++) {

                    String title = Constants.mItem_Detail
                            .get(i).get(
                                    SingleMenuItem.KEY_PNAME);

                    String qty = Constants.mItem_Detail.get(i)
                            .get(SingleMenuItem.KEY_QTY);

                    String cost = Constants.mItem_Detail.get(i)
                            .get(SingleMenuItem.KEY_PRICE);

                    String total = Constants.mItem_Detail
                            .get(i).get(
                                    SingleMenuItem.KEY_TOTAL);

                    body.append("<tr>" + "<td>" + title
                            + "</td><td>" + qty + " * " + cost
                            + "</td>" + " = <td>" + total
                            + "  " + "</td></tr>");
                }

                body.append("<tr>" + "<td>" + "Grand Total is:-  "
                        + "</td><td>" + mGrandTotal + " "
                        + "</td></tr>");
                body.append("</table></body></html>");
            message.setContent(body);
             Transport.send(message);                   
        System.out.println("Done");

            } catch (MessagingException e) {
                throw new RuntimeException(e);
            }
           }

我已经更改了上面的代码。这里我必须得到以下错误:

Part 类型中的方法 setContent(Multipart) 不适用于参数(StringBuilder)

在这些线上 message.setContent(body);

如何清除这些错误。请帮助我。如何使用 javamail api 从我的 android 应用程序发送多个产品详细信息。

4

0 回答 0