[英]Error empty content gmail using javamail api send email smtp
我正在工作的项目:jsf,richfaces。 我刚刚在https://java.net/projects/javamail/pages/Home更新了javamail api的最新版本1.5.5,当我测试将电子邮件从gmail发送到gmail时,主题: 主题测试 。 内容: 内容测试 。 和配置: smtp.gmail.com , 465 , SSL 。 它只有主题,收件箱中没有内容收到gmail:
并记录:
和我的代码:
try {
MailSSLSocketFactory sf = new MailSSLSocketFactory();
sf.setTrustAllHosts(true);
final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
// Set the host smtp address
props.put("mail.smtp.host", SMTP_HOST_NAME);
props.put("mail.smtp.port", SMTP_PORT);
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.socketFactory.class", SSL_FACTORY);
props.put("mail.smtp.socketFactory.port", SMTP_PORT);
props.put("mail.smtp.ssl.trust", "*");
props.put("mail.smtp.ssl.socketFactory", sf);
} catch (GeneralSecurityException e) {
e.printStackTrace();
}
.......
.......
Authenticator auth = new SMTPAuthenticator();
Session session = Session.getInstance(props, auth);
session.setDebug(true);
// create a message
MimeMessage msg = new MimeMessage(session);
msg.setText("UTF8");
// set the from and to address
InternetAddress addressFrom = new InternetAddress(SMTP_AUTH_USER);
msg.setFrom(addressFrom);
System.out.println(addressFrom);
msg.setSubject(subject, "utf-8");
......
......
try {
String content = replaceCharacterInEmail(cus, null,null, message);
MimeBodyPart mbp1 = new MimeBodyPart();
mbp1.setContent(content, "text/html; charset=utf-8");
// attach the file to the message
Multipart mp = new MimeMultipart();
int count = 0;
if(files != null){
while (count < files.size()) {
MimeBodyPart mbdp = new MimeBodyPart();
mbdp.attachFile(files.get(count));
mp.addBodyPart(mbdp);
count++;
}
}
// create the Multipart and add its parts to it
mp.addBodyPart(mbp1);
// add the Multipart to the message
msg.setContent(mp);
Transport.send(msg);
} catch (Exception e) {
invalidAddress += (", " + address.trim());
e.printStackTrace();
}finally{
if (!"".equals(emailFails)) {
emailFails = emailFails.substring(1);
}
}
但是,当我使用上述lib javamail在另一个项目测试(java应用程序)中测试以上代码时。 没关系 : 。
我认为lib javamail版本没有问题。 我不知道两个项目之间的区别,因为部分发送电子邮件是相似的。 我该如何解决该错误?
请遵守以下电子邮件结构:-多部分/混合-mutlipart / alternative-文本/纯文本-文本/ html-应用程序/八位字节流(或其他任何模仿类型)
我发现问题是jboss服务器的lib和app.ear的lib(部署)的冲突库。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.