How can I send an html message using Java mail

前端 未结 1 582
情深已故
情深已故 2021-01-19 01:38

Ive been sending plaintest email from Java no problem but Im now trying to send a html one as follows:

        MimeMessage message = new MimeMessage(Email.ge         


        
相关标签:
1条回答
  • 2021-01-19 02:12

    You can try the following:

    message.setText(msg, "utf-8", "html");
    

    or

    message.setContent(msg, "text/html; charset=utf-8");
    

    Avoid the setText method, you only need setContent.

    It should be like this:

    MimeMessage message = new MimeMessage(Email.getSession()); 
    message.setFrom(new InternetAddress("support@jthink.net"));
    message.addRecipient(Message.RecipientType.TO, new InternetAddress(to, true));
    message.setSubject(subject);
    message.setContent(msg, "text/html; charset=utf-8");
    message.saveChanges();
    Transport.send(message);
    

    Hope it helps you!

    0 讨论(0)
提交回复
热议问题