html有时不显示在电子邮件中

html有时不显示在电子邮件中,html,email,jakarta-mail,Html,Email,Jakarta Mail,我已经编写了一个java代码来发送html电子邮件。当我一次将电子邮件发送给一组收件人时,电子邮件会按原样显示。下面是相同的代码: String content="<html><p><h1>This is my first java mail with an image but there is a difference.</h1></p><p><img src=\"http://***/ImageLoader2.ph

我已经编写了一个java代码来发送html电子邮件。当我一次将电子邮件发送给一组收件人时,电子邮件会按原样显示。下面是相同的代码:

String content="<html><p><h1>This is my first java mail with an image but there is a difference.</h1></p><p><img src=\"http://***/ImageLoader2.php\"></p></html>";
m.setSubject(subject);
m.setContent(content,"text/html");

InternetAddress[] toAdd=new InternetAddress[to.length];

    for(int i=0;i<to.length;i++)
        toAdd[i]=new InternetAddress(to[i]);

    for (InternetAddress toAdd1 : toAdd)
                m.addRecipient(Message.RecipientType.TO, toAdd1);
            Transport t=s.getTransport("smtp");
            t.connect(host, user, pass);
            t.sendMessage(m, m.getAllRecipients());
            System.out.println("MESAAGES SENT");
    t.close();
除此之外,没有其他显著区别

编辑


我还尝试使用
m.setHeader()
设置标题,但没有成功。

我认为问题在于,您正在为每个收件人重复使用相同的mimessage对象。每次都创建一个新的mimessage对象,我怀疑它会工作得更好。

此外,对于windows live mail,当我使用这两种方法中的任何一种时,电子邮件都能正确显示。你能突出显示正在运行的示例和已损坏的示例之间的消息源差异吗?Gmail有一个选项,可以通过单击向下箭头并选择
Show original
来查看原始内容。对两者都这样做,并进行比较。后者可能没有有效的html或内容类型设置不正确。@tripleee,请查看edit@StepanGrigoryan你说得对,这封破损的电子邮件缺少标题。但为什么呢?这很有效!但是为什么呢?为什么每次我重用对象时都会删除内容类型标题?我的实现有问题吗,还是与MIME对象itslef的实现有关?我也试着每次都重新设置标题,但都不起作用。我不知道为什么原始版本会失败;这将需要更多的调试。我认为这与saveChanges没有被调用有关。通常在发送时隐式调用它,但这只在第一次发生。
m.setSubject(subject);
Transport t=s.getTransport("smtp");
    t.connect(host, user, pass);

            for(int i=0;i<to.length;i++){
                content="<html><p><h1>This is my first java mail with an image but there is a difference.</h1></p><p><img src=\"http://***/ImageLoader2.php?uid="+to[i]+"\"></p></html>";
                InternetAddress toAdd=new InternetAddress(to[i]);
                m.setRecipient(Message.RecipientType.TO, toAdd);
                m.setContent(content,"text/html");
                t.sendMessage(m, m.getAllRecipients());
            }           

            System.out.println("MESAAGES SENT");
    t.close();
        }
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit