HTML不会使用Javax呈现

时间:2014-01-30 21:27:46

标签: java html javax.mail

为什么不解释这个问题?我使用StringBuilder.append()来构建电子邮件&发送它,它显示为文本。这是一个片段。

    notificationEmail.append("Mr. " +salesOpsInfo[1]+ " " + salesOpsInfo[2] + '\n'); 
    notificationEmail.append(salesOpsInfo[0] + '\n');
    notificationEmail.append( "\n\n");
    notificationEmail.append("Dear Mr. "+ salesOpsInfo[2] + ","  + "\n");

    notificationEmail.append("" + '\n');
    notificationEmail.append(EndOfLicenseRenewal.eolTextBeforeTable());
    NotificationUtil.**sendMail**(salesOps_email_list, attachmentList, subject, salesOpsEmail.toString(), "eolnotification@DOMAIN.com", "mail.MYSERVER.com", false);

sendMail是发送的标准方式..

        try
    {
        MimeMessage msg = new MimeMessage(session);
        if ((from != null) && (!from.equalsIgnoreCase(" "))) {
            msg.setFrom(new InternetAddress(from));
        }
        InternetAddress[] address = new InternetAddress[recipients.size()];
        for (int i = 0; i < recipients.size(); i++)
        {
            String rec = (String)recipients.get(i);
            if ((rec != null) && (!rec.equalsIgnoreCase(""))) {
                address[i] = new InternetAddress((String)recipients.get(i));
            }
        }
        msg.setRecipients(Message.RecipientType.TO, address);
        msg.setSubject(subject);


        MimeBodyPart mbpMessage = new MimeBodyPart();
        **mbpMessage.setContent(message, "text/html");**
        mbpMessage.setHeader("Content-ID", "<memememe>");


        Multipart mp = new MimeMultipart();
        mp.addBodyPart(mbpMessage);
        if (attachments != null) {
            for (int i = 0; i < attachments.size(); i++)
            {
                MimeBodyPart mbp = new MimeBodyPart();


                FileDataSource fds = new FileDataSource((String)attachments.get(i));
                mbp.setDataHandler(new DataHandler(fds));
                mbp.setFileName(fds.getName());
                mbp.setHeader("Content-ID", "<memememe>");

                mp.addBodyPart(mbp);
            }
        }
        msg.setContent(mp);


        msg.setSentDate(new Date());

        Transport.send(msg);

据我所知(text / html)应该正确发送它我想要的...而不是在电子邮件中我得到

you may contact our dedicated team at <u>eolnotification@DOMAIN.com </u>

编辑: 只是尝试了,他们也没有工作。

        mbpMessage.setContent(message, "text/html");
        mbpMessage.setHeader("Content-ID", "text/html");

.saveChanges()似乎不适用于MimeBodyPart

1 个答案:

答案 0 :(得分:0)

设置内容后尝试调用mbpMessage.saveChanges()。