java
  • html
  • email
  • 2013-03-11 123 views 0 likes 
    0

    我使用下面的代码在浏览器中运行良好,但不显示为正确格式化在Outlook:发送HTML邮件正文支持从Outlook Java邮件

    MimeMultipart mimeMultipart = new MimeMultipart(); 
    MimeBodyPart bodyPart = new MimeBodyPart(); 
    
    bodyPart.setText("<html><body><font size='3px' face='Times New Roman'>" 
        + removeMultipleSpaces(msgbody) + "</font></body></html>"); 
    mimeMultipart.addBodyPart(bodyPart); 
    bodyPart.setDescription("Text"); 
    bodyPart.setHeader("Content-Type", "text/html; charset=utf-8"); 
    
    +0

    你能解释一下多一点实际的问题是什么? – 2013-03-11 11:22:33

    +1

    这可能是因为支持Outlook,请尝试在这里查看是否支持所有内容; http://www.campaignmonitor.com/css/ – Andy 2013-03-11 11:23:47

    +0

    但问题是什么? _What_显示不正确,确切_how_不正确?另外,你发布的内容似乎没问题,'msgBody'的内容会很有趣... – ppeterka 2013-03-11 12:57:57

    回答

    0

    当您在评论提到,你想要添加图片。为图像创建一个MimeBodyPart的,创建一个CID,并且做对图像的MimeBodyPart的setContentID:

    import javax.mail.internet.*; 
    
    MimeMultipart content = new MimeMultipart("related"); 
    
    MimeBodyPart mainPart = new MimeBodyPart(); 
    mainPart.setText("<html><body><img src=\"cid:[email protected]\"></body></html>","UTF-8", "html"); 
    content.addBodyPart(mainPart); 
    
    MimeBodyPart imagePart = new MimeBodyPart(); 
    
    java.net.URL img1 = Example.class.getClassLoader().getResource("image.png"); 
    imagePart.setDataHandler(new DataHandler(img1)); 
    //or: 
    //imagePart.attachFile("resources/image.png"); 
    
    imagePart.setContentID("<[email protected]>"); // to embed 
    imagePart.setDisposition(MimeBodyPart.INLINE); // to embed 
    content.addBodyPart(imagePart); 
    
    相关问题