我试图以HTML格式发送电子邮件。它正在为文本/纯文本工作。但是,当我设置内容类型为文本/ HTML邮件没有被运输(没有例外被抛出,但我也没有收到电子邮件)。 以下是我的代码。无法以HTML格式发送电子邮件。
public void postMail() throws Exception {
boolean debug = false;
Properties props = new Properties();
props.put("mail.smtp.host", smtpServer);
props.put("mail.smtp.port", smtpServerPort);
props.put("mail.smtp.auth", "false");
props.put("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.socketFactory.fallback","false");
lgr.debug(lgr.isDebugEnabled()?"SMTP Server --->" + smtpServer : null);
Session session = Session.getInstance(props, null);
session.setDebug(debug);
Message msg = new MimeMessage(session);
InternetAddress addressFrom = new InternetAddress(from);
msg.setFrom(addressFrom);
// Here is some logic to add TO and CC and BCC
msg.setSubject(subject);
// writer.println("Subject : " + subject);
lgr.debug(lgr.isDebugEnabled()?"Subject : " + subject : null);
msg.setContent(message, "text/html");
Transport.send(msg);
lgr.info(lgr.isInfoEnabled() ?"Mail sent": null);
}
在这方面的任何帮助将不胜感激。
你可以放置你试图通过对电子邮件的一些样本邮件内容.. – Pandian
以下是内容
您好所有, 缓存在成功刷新[周一4月1日19时25分41秒PKT 2013] 。 需要注意的是,大约[100]分钟后缓存将再次刷新。 请注意这是一条信息性消息,系统已启动并正在运行。 – Jabir