0
 int count=1;
    msg = "No.   Desc.        Code   Size   Cost    Qty    Amount";
    for(Products p:list){
        msg += count+"   "+p.desc+"    "+p.code+"  "+p.size+"  "+p.cost+"  "+p.qnty+"  "+p.amnt;
        count ++;
    }

    try {
        Message msg = new MimeMessage(ses);
        msg.setFrom(new InternetAddress("samashanayananthi@gmail.com"));//from mail address
        msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse("samasha.2017323@iit.ac.lk"));//to mail address
        msg.setSubject("Tax Invoice");//set the mail subject
        msg.setContent("<h:body style=background-color:white;font-family:verdana;>"+"<h1 style=\"padding-left:500px\"><b>Jeff's Fishing Shack</b></h1>"
                +"<h2 style=\"padding-left:570px\"><b>Tax Invoice</b></h2>"+"<p style=\"padding-left:80px\">Jeff’s Fishing Shack<br>Trading as: Octopus Pty Ltd<br>Shop 4, Hillarys Boat Harbour<br>Hillarys, WA, 6025<br>T: 08 9402 2222<br>Email:\tSales@JFS.com.au</p>\n"
                + "<p style=\"padding-left:80px\">Reciepts#:  </p> <p style=\"padding-left:1000px\">Date :</p>\n"+"<p style=\"padding-left:80px\">Customer :</p>\n"+"<p style=\"padding-left:80px\">Customer# :</p>\n"
                +"<p style=\"padding-left:80px\">Customer email :</p>\n"+"<p style=\"padding-left:80px\">Purchases</p>\n"
                +"<div style=\"padding-left:80px; padding-right:80px\">"+msg+"</div>\n"+"<p style=\"padding-left:800px\">Total paid : </p>\n"
                +"<p style=\"padding-left:700px\">Thank you for your business.<br>Jeff’s - where the real fishermen shop.</p>\n"
                + "</body>", "text/html; charset=utf-8");

When I send the message, I'm receiving the message correctly. But in my code I added a msg variable and I tried to add it to the mail body.

My msg variable is not displaying in the mail. I'm getting a message saying,javax.mail.internet.MimeMessage@772ef644.

How can I fix it and what did I do wrong?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Samasha
  • 369
  • 1
  • 5
  • 16
  • `msg` inside msg content, what a strange idea ? This is a duplicate, but i don't find it .. of using the default toString() method – azro Jul 29 '18 at 12:41
  • Please include the full code, the code shown doesn't add the `msg` variable to the message, nor does it send the message. The basic reason is the duplicate linked by azro, but the solution also depends on what you want to do with the message (attach it, just include the content, etc). – Mark Rotteveel Jul 29 '18 at 13:10
  • You are getting the default output of `Object.toString()`, `MimeMessage` (nor its superclasses) override it. – Mark Rotteveel Jul 29 '18 at 13:16
  • Thank you very much for the help.I got it now – Samasha Jul 29 '18 at 13:21

0 Answers0