[英]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.