How to send html email to outlook from Java

前端 未结 8 2036
忘掉有多难
忘掉有多难 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:56
    message.setContent(new String(sBuffer.toString().getBytes(), "iso-8859-1"), "text/html; charset=iso-8859-1");
    

    Should solve your problem (removed \" characters).

    0 讨论(0)
  • 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")
    
    0 讨论(0)
提交回复
热议问题