• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Java Mail - HTML email not working showing as plain text

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I am using the below code and despite multiple attempts the email is not being shown in "html" format but is always being showing as plain text format:



Output of the above code (<h1> tag is not getting parsed and is being displayed as a plain text): <h1> test email </h1>

Also tried the following options but none of them actually worked:



  • Same problem with this approach as well:
    message.setContent(msgData, "text/html; charset=utf-8");



  • MimeBodyPart htmlPart = new MimeBodyPart();
    String htmlContent = "<html><h1>Hi</h1><p>Nice to meet you!</p></html>";
    htmlPart.setContent(htmlContent, "text/html");


  • Any advice on this will be greatly appreciated.




     
    Sheriff
    Posts: 28322
    95
    Eclipse IDE Firefox Browser MySQL Database
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Start with the JavaMail FAQ page from Oracle. One of the questions there is "How do I send HTML mail?" which seems like a good start for your search.
     
    Rahul Chaitanya
    Ranch Hand
    Posts: 39
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    I tried the oracle mail api that you mentioned but still I am seeing the same issue, that the <html> is being displayed in the form of plain text itself and pasting the logs below:


    Loading javamail.default.providers from jar:/javax/mail/mail/1.4/mail-1.4.jar!/META-INF/javamail.default.providers
    DEBUG: loading new provider protocol=imap, className=com.sun.mail.imap.IMAPStore, vendor=Sun Microsystems, Inc, version=null
    DEBUG: loading new provider protocol=imaps, className=com.sun.mail.imap.IMAPSSLStore, vendor=Sun Microsystems, Inc, version=null
    DEBUG: loading new provider protocol=smtp, className=com.sun.mail.smtp.SMTPTransport, vendor=Sun Microsystems, Inc, version=null
    DEBUG: loading new provider protocol=smtps, className=com.sun.mail.smtp.SMTPSSLTransport, vendor=Sun Microsystems, Inc, version=null
    DEBUG: loading new provider protocol=pop3, className=com.sun.mail.pop3.POP3Store, vendor=Sun Microsystems, Inc, version=null
    DEBUG: loading new provider protocol=pop3s, className=com.sun.mail.pop3.POP3SSLStore, vendor=Sun Microsystems, Inc, version=null
    Loading javamail.default.providers from jar:file:/C:/FAST/fastas/3.3.2/default/fcBase/repo/com/sun/mail/javax.mail/1.5.2/javax.mail-1.5.2.jar!/META-INF/javamail.default.providers
    DEBUG: loading new provider protocol=imap, className=com.sun.mail.imap.IMAPStore, vendor=Oracle, version=null
    DEBUG: loading new provider protocol=imaps, className=com.sun.mail.imap.IMAPSSLStore, vendor=Oracle, version=null
    DEBUG: loading new provider protocol=smtp, className=com.sun.mail.smtp.SMTPTransport, vendor=Oracle, version=null
    DEBUG: loading new provider protocol=smtps, className=com.sun.mail.smtp.SMTPSSLTransport, vendor=Oracle, version=null
    DEBUG: loading new provider protocol=pop3, className=com.sun.mail.pop3.POP3Store, vendor=Oracle, version=null
    DEBUG: loading new provider protocol=pop3s, className=com.sun.mail.pop3.POP3SSLStore, vendor=Oracle, version=null
    DEBUG: getProvider() returning provider protocol=smtp; type=javax.mail.Provider$Type@6a70122; class=com.sun.mail.smtp.SMTPTransport; vendor=Sun Microsystems, Inc
    DEBUG SMTP: useEhlo true, useAuth false
    DEBUG SMTP: trying to connect to host "mailhost.testdomain.net", port 25, isSSL false
    220 se2.svr.bankone.net ESMTP Sendmail Sentrion-MTA-4.3.1/Sentrion-MTA-4.3.1; Fri, 3 Jun 2016 21:28:06 GMT
    DEBUG SMTP: connected to host "mailhost.testdomain.net", port: 25

    EHLO L3SR7P12
    s250-se2.svr.bankone.net Hello [10.181.201.114], pleased to meet you
    250-ENHANCEDSTATUSCODES
    250-PIPELINING
    250-8BITMIME
    250-SIZE 41943040
    250-ETRN
    250-STARTTLS
    250-DELIVERBY
    250 HELP
    DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
    DEBUG SMTP: Found extension "PIPELINING", arg ""
    DEBUG SMTP: Found extension "8BITMIME", arg ""
    DEBUG SMTP: Found extension "SIZE", arg "41943040"
    DEBUG SMTP: Found extension "ETRN", arg ""
    DEBUG SMTP: Found extension "STARTTLS", arg ""
    DEBUG SMTP: Found extension "DELIVERBY", arg ""
    DEBUG SMTP: Found extension "HELP", arg ""
    DEBUG SMTP: use8bit false
    MAIL FROM:<test@test.com>
    250 2.1.0 <test@test.com>... Sender ok
    RCPT TO:<test@test.com>
    t250 2.1.5 <test@test.com>... Recipient ok
    DEBUG SMTP: Verified Addresses
    DEBUG SMTP: test@test.com
    DATA
    354 Enter mail, end with "." on a line by itself

    <HTML>
    <HEAD>
    <TITLE>
    test
    </TITLE>
    </HEAD>
    <BODY>
    <h1>test</h1>


    </BODY>
    </HTML>

    .
    250 2.0.0 u53LS6QQ003721 Message accepted for delivery
    QUIT

    Mail was sent successfully.
     
    Paul Clapham
    Sheriff
    Posts: 28322
    95
    Eclipse IDE Firefox Browser MySQL Database
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    And no matter what e-mail address you send that message to, and no matter what e-mail client you use to read it, the same thing happens?
     
    Sheriff
    Posts: 4639
    582
    VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    It might be that you are missing the Content-Type: text/html header.


     
    Rahul Chaitanya
    Ranch Hand
    Posts: 39
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi,

    Can you please, share the code?

    I tried both the below options but still the same issue:



    Thank you.
     
    Rancher
    Posts: 4801
    50
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    How are you testing this?
    Essentially Paul's question...does this happen on a number of different email recipients, including different hosts, applications, etc.
     
    Rahul Chaitanya
    Ranch Hand
    Posts: 39
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi Paul,

    Yes, no matter to whom I send the email or irrespective of the email clients, I am seeing the same issue.

    Thanks.
     
    Bartender
    Posts: 3648
    16
    Android Mac OS X Firefox Browser Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    You need to use the MimeBodyPart and MimeMultipart for the email body to control whether it's plain text or html or whatever. The UTF-8 encoding can also be set.

     
    Rahul Chaitanya
    Ranch Hand
    Posts: 39
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    This is the response, I am getting with the above code:


    ------=_Part_0_735891530.1465314350219
    Content-Type: text/plain; charset=UTF-8
    Content-Transfer-Encoding: 7bit

    some body
    ------=_Part_0_735891530.1465314350219--


    Still no luck
     
    Ron McLeod
    Sheriff
    Posts: 4639
    582
    VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Rahul Chaitanya wrote:.. no matter to whom I send the email or irrespective of the email clients, I am seeing the same issue.


    Rahul -- what email client are you using and on what platform?
     
    Rahul Chaitanya
    Ranch Hand
    Posts: 39
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi,

    I am using Microsoft outlook on windows machine. Let me know, if I need to provide any more information?

    Thanks.
     
    Ron McLeod
    Sheriff
    Posts: 4639
    582
    VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
    • Likes 1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Rahul Chaitanya wrote:Can you please, share the code?


    Well .. I just took your original code, changed the SMTP host and the To/From addresses, and ran it. Using Outlook, I did see the HTML rendered (even when the HTML wasn't a proper document).



    My email server is sendmail 8.13; client is MS Outlook 14.0 (part of Office 2010).
     
    Rahul Chaitanya
    Ranch Hand
    Posts: 39
    • Likes 1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Thank you. Fixing the different MAIL related jar file in the classpath helped to fix the issue.
     
    Ranch Hand
    Posts: 658
    2
    Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Rahul Chaitanya wrote:Thank you. Fixing the different MAIL related jar file in the classpath helped to fix the issue.


    Hi Rahul,
    Which mail jar you used to resolve this issue. I am facing the same issue with javax.mail
     
    Greenhorn
    Posts: 5
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    In my case it was due to https://issues.apache.org/jira/browse/GERONIMO-6536. So excluded Geronimo library to fix it.
     
    The knights of nee want a shrubbery. And a tiny ad:
    Gift giving made easy with the permaculture playing cards
    https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
    reply
      Bookmark Topic Watch Topic
    • New Topic