0

I would like to send an email with HTML table format.

I am trying to send an email in HTML format. It's working fine when I run through Eclipse IDE. But when I try to run through Apache Tomcat Directory(put the project inside WebApp folder and then run the server) then it send the email which shows the html code, it doesn't shows the rich text itself.

Java Code:

MimeMessage message = new MimeMessage(session);

                        String mail = (String) recipientMails.nextElement();
                        // System.out.println(mail);

                        message.addRecipient(Message.RecipientType.TO, new InternetAddress(mail));

                        message.setSubject(subject + " -: " + submission.getSubmissionName());

                        message.setContent(htmTemp + "<tr><td>" + submission.getSubmissionName() + "</td><td>" + submission.getStatus() + "</td><td>" + messg + "</td></tr>" + "</table></body></html>", "test/html");

                        logger.error(subject + "SendTo:" + recipientMail + "\n" + messg);

                        Transport.send(message);

Actual Output: (which comes wrong when running through Tomcat Directory)

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<style>
table,th,td {
    border: 1px solid black;
    border-collapse: collapse;
}

th,td {
    padding: 5px;
}
</style>![enter image description here][1]
</head>
<body>
    <table style="width: 100%">
        <tr>
            <th>Submission Name</th>
            <th>Status</th>
            <th>Details</th>
        </tr><tr><td>ELQ_1423749204038</td><td>Sent For Translation</td><td>Your submission has been sent successfully for translation.</td></tr></table></body></html>

Expected Output:(which comes fine when running through Eclipse IDE)

See the below image:

1 Answers1

1

You have a typo in you're mime type. Should read text/html not test/html in the line message.setContent(...

  • May http://stackoverflow.com/questions/5068827/how-do-i-send-html-email-via-java is helpful. There are some comments regarding this problem. – Andreas Vogler Feb 13 '15 at 14:44