2009-11-12 114 views

回答

10

啊,你使用的是Java。

請注意,在我看來,您應該始終在HTML電子郵件中設置純文本替代。

此代碼,您還可以內置圖片(從HTML與<img src="cid:foo">參考,但不是所有的電子郵件客戶端支持此功能。

MimeMessage mm = prepareMessage(from, to, subject, cc, bcc); 
MimeMultipart mp = new MimeMultipart("alternative"); 

// Attach Plain Text 
MimeBodyPart plain = new MimeBodyPart(); 
plain.setText(plainText); 
mp.addBodyPart(plain); 

/* 
* Any attached images for the HTML portion of the email need to be encapsulated with 
* the HTML portion within a 'related' MimeMultipart. Hence we create one of these and 
* set it as a bodypart for the overall message. 
*/ 
MimeMultipart htmlmp = new MimeMultipart("related"); 
MimeBodyPart htmlbp = new MimeBodyPart(); 
htmlbp.setContent(htmlmp); 
mp.addBodyPart(htmlbp); 

// Attach HTML Text 
MimeBodyPart html = new MimeBodyPart(); 
html.setContent(htmlText, "text/html"); 
htmlmp.addBodyPart(html); 

// Attach template images (EmailImage is a simple class that holds image data) 
for (EmailImage ei : template.getImages()) { 
    MimeBodyPart img = new MimeBodyPart(); 
    img.setContentID(ei.getFilename()); 
    img.setFileName(ei.getFilename()); 
    ByteArrayDataSource bads = new ByteArrayDataSource(ei.getImageData(), ei.getMimeType()); 
    img.setDataHandler(new DataHandler(bads)); 
    htmlmp.addBodyPart(img); 
} 

mm.setContent(mp); 
1

您正在將電子郵件的那部分內容類型mime設置爲text/html嗎?

或者,您正在使用Outlook查看 - Outlook的查看器使用Word來呈現HTML,而不是像任何合理的設計那樣使用IE呈現引擎。這確實意味着可能會丟失重要的格式。

另外,嘗試不同的字體。幾種字體不定義粗體變體。儘管這是一個長鏡頭,但大多數字體渲染技術都可以自動加粗非粗體字體。

1

您使用哪種編程語言發送電子郵件。

任何語言的選項都應該像「IsBodyHtml」那樣。要做到「真」這個檢查。類似.NET代碼

System.Net.Mail.MailMessage mm = new System.Net.Mail.MailMessage(); mm.IsBodyHtml = true;

因此,郵件將作爲html文本。

+0

我用java – Harish 2009-11-12 10:34:53

1

對這個問題有一個明確的答案有點困難。事情可能無法正常工作的原因有很多。這些是您可以檢查以嘗試隔離問題的一些事情。

是否識別了其他的html標籤?例如。 <p><a>?如果是這樣,您是否嘗試過使用<strong>標籤而不是<b>

檢查電子郵件閱讀器中的消息源。也許'<'或'>'字符已被轉義爲'& lt;'或'& gt;'在發送之前。

您是否嘗試在不同的閱讀器中查看電子郵件,例如基於webmail或桌面?

嘗試使用CSS來改變字體重量:

.important-text { font-weight: bold; } 

<span class=".important-text">Super important text</span>