我寫了一個java代碼來發送html電子郵件。當我一次將電子郵件發送給一組收件人時,電子郵件會按照它的顯示方式顯示。下面是相同的代碼: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();
而這裏的輸出:
first http://i58.tinypic.com/33ejtvq.png 現在,這裏就是我單獨發送的電子郵件的代碼:
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();
}
這裏是這個代碼的輸出:
second http://i60.tinypic.com/21b7nz8.png 這是爲什麼發生?我知道css經常在網絡郵件系統上打破,但我沒有使用任何。谷歌也沒有任何幫助。
感謝
編輯
在被破壞的郵件,這些領域中缺少標題:
比Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit
其他,沒有其他signifiacnt差異。
編輯
我也嘗試使用m.setHeader()
設置標頭,但沒有奏效。
此外,對於Windows Live郵件,當我使用這兩種方法時,電子郵件都會正確顯示 –
您是否可以突出顯示正在工作和已損壞示例之間的消息源的差異? – tripleee
Gmail可以通過點擊向下箭頭並選擇「顯示原創」來查看原始內容。爲兩者做這件事並進行比較。有可能後者沒有有效的html或內容類型設置不正確。 –