2016-03-31 3 views
0

Ich arbeite Projekt: JSF, Richfaces. Ich habe gerade aktualisiert javamail api neueste Version 1.5.5 um https://java.net/projects/javamail/pages/Home Wenn ich Test sende E-Mail von Gmail zu meinem Gmail, Betreff: Subject Test. Inhalt: Inhaltstest. Und config: smtp.gmail.com, , SSL. Es hat nur Subjekt und keine Inhalte in meinem Posteingang erhalten gmail:Fehler leeren Inhalt Gmail mit Javamail API senden E-Mail SMTP

enter image description here

Und log:

enter image description here

Und mein Code:

  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); 
        } 
       } 

Aber, wenn ich obigen Code bei einem anderen Projekttest teste (Java App lication) mit über lib javamail. Es ist in Ordnung: enter image description here.

Ich glaube nicht, Problem bei der Version von Lib Javamail. Ich weiß nicht, zwischen 2 Projekt anders, weil Teil senden E-Mail ist ähnlich. Wie kann ich diesen Fehler beheben?

Antwort

0

Bitte beachten Sie diese E-Mail-Struktur: - multipart/mixed - mutlipart/alternative - text/plain - text/html - application/Octet-Stream (oder andere MIME-Typen)

+0

Sorry für meine Frage ist nicht klar. Ich habe festgestellt, Problem ist Konfliktbibliothek in der lib von jboss Server und lib von app.ear (deploy). – TungHarry

0

Ich habe festgestellt, Problem ist Konflikt Bibliothek in der lib von jboss Server und lib von app.ear (deploy).

+0

Froh, dass Sie es herausgefunden haben. Beachten Sie, dass Sie alle ** Socket-Factory-Eigenschaften und Variablen in Ihrem Programm loswerden können **; Sie sollten keine von ihnen brauchen. –

Verwandte Themen