【總結】OUTLOOK2016郵件樣式和inline圖片兼容性等問題解決


Div布局不支持

outlook客戶端很多都不支持div布局。應該全部換成table布局。

line-height不生效

解決方案

  • mso-line-height-rule: exactly;

  • 在空的單元格中加入空格HTML轉義符: 

例如一個水平帶顏色的條:

<td height="3"
          width="100%"
          style="mso-line-height-rule: exactly; line-height: 3px; background-color: #1890ff;"
        >&nbsp;</td>

如果沒有加&nbsp;則藍色高度會無效

inline圖片不顯示,或者顯示為紅叉

解決方案
https://support.microsoft.com/en-us/help/2779191/inline-images-may-display-as-a-red-x-in-outlook
對於Microsoft Outlook 2016和2013:
該問題的原因:如果未設置以下注冊表值,或者不存在以下注冊表值:

HKEY_CURRENT_USER\Software\Microsoft\Office\x.0\Outlook\Options\Mail

DWORD Key :Send Pictures With Document

值:1

注意:x.0是占位符,需要根據版本選擇正確的值:16.0 = Office 2016, 15.0 = Office 2013

Logo等圖片不顯示(二)

如果圖片或者Logo是Inline的,例如base64編碼的圖片,在瀏覽器中是顯示的,但是在Outlook 2016等客戶端是無法顯示的。

<img width="45px" height="45px" src="data:image/png;base64,iVBORSLANKKA...."/>

解決方案:
替換成inline附件:

String imgSrc = item.attr("src");
String dataType = StringUtils.substringBetween(imgSrc, "data:", ";base64,"); // extract data type (dataType = "image/png")
String base64EncodedFileContent = imgSrc.replaceFirst("data:.*;base64,", ""); // remove prefix from fileContent String (base64EncodedFileContent = "iVBORSLANKKA......etc"

MimeBodyPart filePart = new PreencodedMimeBodyPart("base64");
filePart.setContent(base64EncodedFileContent, dataType);
filePart.setFileName("attachImg"+ (++i) +"." + dataType.substring(dataType.lastIndexOf('/')));
IdGenerator idGenerator = new AlternativeJdkIdGenerator();
String cid = idGenerator.generateId().toString();
filePart.setContentID("<" + cid + ">");
filePart.setDisposition(MimeBodyPart.INLINE);
item.attr("src", "cid:"+ cid);
mainPart.addBodyPart(filePart);

則郵件中的BASE64編碼可以轉換成PreencodedMimeBodyPart,作為INLINE的附件,通過Cid引用。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM