简体   繁体   中英

Error empty content gmail using javamail api send email smtp

I'm working project : jsf, richfaces. I has just updated javamail api newest version 1.5.5 at https://java.net/projects/javamail/pages/Home When i test send email from gmail to my gmail, Subject : Subject test . Content : Content test . And config : smtp.gmail.com , 465 , SSL . It has just subject and no content in my inbox receive gmail :

在此处输入图片说明

And log :

在此处输入图片说明

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

But, when i test above code at another project test (java application) with above lib javamail. It's ok : 在此处输入图片说明 .

I don't think problem at version of lib javamail. I don't know different between 2 project, because part send email is similar. How can i fix that error ?

请遵守以下电子邮件结构:-多部分/混合-mutlipart / alternative-文本/纯文本-文本/ html-应用程序/八位字节流(或其他任何模仿类型)

我发现问题是jboss服务器的lib和app.ear的lib(部署)的冲突库。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM