1. Download our Official Android App: Forums for Android!

Apps send more than one items to mail from android application

Discussion in 'Android Development' started by krishnaveni, Jan 17, 2013.

  1. krishnaveni

    krishnaveni Well-Known Member
    Thread Starter
    Rank:
    None
    Points:
    55
    Posts:
    158
    Joined:
    Dec 16, 2011

    Dec 16, 2011
    158
    0
    55
    chennai
    I have to develop one android example.

    More than one item detail is send to mail from my android application.

    Here i have to run the app means the latest added product detail alone send to mail.but i have to send the all added product detail is send to email.How can i do.please help me.whats wrong in my code.please check the code and give me solution for these.

    I have used below code:
    HTML:
    1.  
    2. public class InvoiceOrder extends Activity {
    3.  
    4.    
    5.     String mGrandTotal;
    6.  
    7.     @Override
    8.     protected void onCreate(Bundle savedInstanceState) {
    9.         // TODO Auto-generated method stub  
    10.         super.onCreate(savedInstanceState);
    11.         setContentView(R.layout.invoice);
    12.         ListView mLstView1 = (ListView) findViewById(R.id.listView1);
    13.  
    14.  
    15.         CustomerAdapter mViewCartAdpt = new CustomerAdapter(
    16.                 InvoiceOrder.this);
    17.         mLstView1.setAdapter(mViewCartAdpt);
    18.        
    19.                 Button login = (Button) findViewById(R.id.mBtnSubmit);
    20.                 login.setOnClickListener(new View.OnClickListener() {
    21.            
    22.             public void onClick(View arg0) {
    23.                 Properties props = new Properties();
    24.                 props.put("mail.smtp.host", "smtp.gmail.com");
    25.                 props.put("mail.smtp.socketFactory.port", "465");
    26.                 props.put("mail.smtp.socketFactory.class",
    27.                         "javax.net.ssl.SSLSocketFactory");
    28.                 props.put("mail.smtp.auth", "true");
    29.                 props.put("mail.smtp.port", "465");
    30.  
    31.                 Session session = Session.getDefaultInstance(props,
    32.                     new javax.mail.Authenticator() {
    33.                         protected PasswordAuthentication getPasswordAuthentication() {
    34.                             return new PasswordAuthentication("krishnaveniv96@gmail.com","xxxxxx");
    35.                         }
    36.                     });
    37.  
    38.                 try {
    39.  
    40.                     Message message = new MimeMessage(session);
    41.                     message.setFrom(new InternetAddress("krishnaveniv96@gmail.com"));
    42.                     message.setRecipients(Message.RecipientType.TO,
    43.                             InternetAddress.parse("mercy.krishnaveni@gmail.com"));
    44.                     message.setSubject("Testing Subject");
    45.                     StringBuilder sb = new StringBuilder();                  
    46.                   //  message.setContent("This is your product name : "+
    47.                         //    "Hi Krishna" +"<br></br>This is your price : "+ "Hi veni", "text/html; charset=utf-8");
    48.                     for (int i = 0; i < Constants.mItem_Detail
    49.                            .size(); i++) {
    50.  
    51.                        String title = Constants.mItem_Detail
    52.                                .get(i).get(
    53.                                        SingleMenuItem.KEY_PNAME);
    54.  
    55.                        String qty = Constants.mItem_Detail.get(i)
    56.                                .get(SingleMenuItem.KEY_QTY);
    57.  
    58.                        String cost = Constants.mItem_Detail.get(i)
    59.                                .get(SingleMenuItem.KEY_PRICE);
    60.  
    61.                        String total = Constants.mItem_Detail
    62.                                .get(i).get(
    63.                                        SingleMenuItem.KEY_TOTAL);
    64.  
    65.                    message.setContent("<tr>" + "<td>" + title
    66.                                 + "</td><td>" + qty + " * " + cost
    67.                                 + "</td>" + " = <td>" + total
    68.                                 + "  " + "</td></tr>", "text/html; charset=utf-8");
    69.                    
    70.                     }
    71.                    
    72.                     Transport.send(message);
    73.  
    74.                     System.out.println("Done");
    75.  
    76.                 } catch (MessagingException e) {
    77.                     throw new RuntimeException(e);
    78.                 }
    79.                }
    80.  
    81.  
    82.  
    83.       });
    84.  
    85.  
     

    Advertisement

  2. krishnaveni

    krishnaveni Well-Known Member
    Thread Starter
    Rank:
    None
    Points:
    55
    Posts:
    158
    Joined:
    Dec 16, 2011

    Dec 16, 2011
    158
    0
    55
    chennai
    Hi
    i got the o/p..The more than one product detail is send to email successfully done.

    These is code :
    But the product detail is sent twice in single email...

    like below:

    Rialto: Expose - Natural Cork1 * 31.6 = 31.6 Laura Ashley Kids: LA20016 (Infant/Toddler/Youth)1 * 18.06 = 18.06
    Rialto: Expose - Natural Cork1 * 31.6 = 31.6 Laura Ashley Kids: LA20016 (Infant/Toddler/Youth)1 * 18.06 = 18.06 Grand Total is:- 49.66
    How can i send the product detail is once in single email.whats wrong in my code.please help me.
     

Share This Page

Loading...