How to send html email to outlook from Java

前端 未结 8 2045
忘掉有多难
忘掉有多难 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:34

    workaroung solution solved outlook 2003: This message uses a character set that is not supported by the Internet Service. doesn't display correctly.

    It could be due to the encoding. Most html pages use iso-8859-1 not cp-1252 try changing

    For example, your code is:

    message.setContent(sBuffer.toString(), "text/html");
    

    Change this to:

    message.setContent(new String(sBuffer.toString().getBytes(), "iso-8859-1"), "text/html; charset=\"iso-8859-1\"");
    

    This throws a new checked exception : java.io.UnsupportedEncodingException so you need to declare it to be thrown or catch it. iso-8859-1 is supported so, the exception will never be thrown unless something gets corrupted with your rt.jar.

    Regards, Javeed javeed.mca@gmail.com

提交回复
热议问题