How to send html email to outlook from Java

前端 未结 8 2032
忘掉有多难
忘掉有多难 2021-02-04 04:06

I\'m trying to send an email in html format using JavaMail but it always seems to only display as a text email in Outlook.

Here is my code:

try 
{
    P         


        
8条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-04 04:58

    html.setContent(htmlBody, "text/html");
    html.setHeader("MIME-Version" , "1.0" );
    html.setHeader("Content-Type" , html.getContentType() );
    

    setContent and setHeader("Content-Type", String) do the same thing - is it possible that html.getContentType() is returning something other than text/html?

    Expanding based on comment and @PhilLho & @erickson's answer (geez, I must type slowly), use:

    MimeMultipart content = new MimeMultipart("alternative")
    

提交回复
热议问题