我想发送下面提到的结果给电子邮件,并希望通过电子邮件仔细收到它们。因此我决定使用html代码,但没有结果。如何发送java电子邮件类中的HTML标记?
代码:
公共静态无效sendresult(ShowResultModel showuserresulttable){
final String username = *****
final String password = ******;
Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.port", "587");
Session session = Session.getInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("[email protected]"));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse("[email protected]"));
message.setSubject("Exammer result :" + showuserresulttable.getUsername());
DecimalFormat formatter = new DecimalFormat("#0.00");
String MESSAGE = " ";
double resultpercent = showuserresulttable.getScore() /(double) showuserresulttable.getTotalanswer()*100;
MESSAGE+="<b>Username:</b> " + showuserresulttable.getUsername() + "<br><hr>";
MESSAGE+="<b>Subject</b>" + showuserresulttable.getSubject() + "<br><hr>";
MESSAGE+="<b>Variant :</b>" + showuserresulttable.getVariant() + "<br><hr>";
MESSAGE+="<b>Score of result:</b>" + showuserresulttable.getScore() + "<br><hr>";
MESSAGE+="<b>Total question :</b>" + showuserresulttable.getTotalanswer()+ "<br><hr>";
MESSAGE+="<b> Score percent:</b>" + resultpercent + "<br><hr>";
MESSAGE+="<b>Spendtime:</b>" + showuserresulttable.getSpendtime() + "second" + "<br><hr>";
MESSAGE+="<b>Examdate:</b>" + showuserresulttable.getExamdate() ;
message.setText(MESSAGE);
Transport.send(message);
System.out.println("Mail gonderildi!");
} catch (MessagingException e) {
throw new RuntimeException(e);
}
}
可能的重复[我如何发送HTML电子邮件?](http://stackoverflow.com/questions/5068827/how-do-i-send-an-html-email) –