Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9297779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T22:09:26+00:00 2026-06-18T22:09:26+00:00

I have a Tomcat application that needs to send confirmation emails etc. I have

  • 0

I have a Tomcat application that needs to send confirmation emails etc. I have coded the emailer with Javamail (mail.jar) to send multipart text/html emails. I based the code on the Java EE examples. I’m using the SMTP MTA on the local server.

It works great. In Outlook, I see the HTML version. If I drag it into the Outlook spam folder, I see the text version. So I interpret that as saying it works.

However, if I view the emails in Gmail, I see only the text version. I know the HTML is there (that’s where Outlook got it from). But Gmail is not showing it… I have lots of emails from other systems that show as HTML in Gmail.

Can anyone point me to the spec that shows what I am missing? Are there special headers I need to create?

Thanks

Code looks like this:

Message message = new MimeMessage(session);
Multipart multiPart = new MimeMultipart("alternative");

try {

    MimeBodyPart textPart = new MimeBodyPart();
    textPart.setText(text, "utf-8");

    MimeBodyPart htmlPart = new MimeBodyPart();
    htmlPart.setContent(html, "text/html; charset=utf-8");

    multiPart.addBodyPart(htmlPart);
    multiPart.addBodyPart(textPart);
    message.setContent(multiPart);

    if(from != null){
        message.setFrom(new InternetAddress(from));
    }else
        message.setFrom();

    if(replyto != null)
        message.setReplyTo(new InternetAddress[]{new InternetAddress(replyto)});
    else
        message.setReplyTo(new InternetAddress[]{new InternetAddress(from)});

    InternetAddress[] toAddresses = { new InternetAddress(to) };
    message.setRecipients(Message.RecipientType.TO, toAddresses);
    message.setSubject(subject);
    message.setSentDate(new Date());

    Transport.send(message);

} catch (AddressException e) {
    e.printStackTrace();
    System.out.println("Error: "+e.getMessage());

} catch (MessagingException e) {
    e.printStackTrace();
    System.out.println("Error: "+e.getMessage());

} finally {     
    System.out.println("Email sent!");
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T22:09:27+00:00Added an answer on June 18, 2026 at 10:09 pm

    Solved! It seems according to the multipart MIME spec, the order of the parts are important. They should be added in order from low fidelity to high fidelity. So it seems GMail follows the spec and uses the last part. In my case I had them HTML, Text. I just swapped the order to Text, HTML and Gmail renders it correctly…

    i.e.

    MimeBodyPart textPart = new MimeBodyPart();
    textPart.setText(text, "utf-8");
    
    MimeBodyPart htmlPart = new MimeBodyPart();
    htmlPart.setContent(html, "text/html; charset=utf-8");
    
    multiPart.addBodyPart(textPart); // <-- first
    multiPart.addBodyPart(htmlPart); // <-- second
    message.setContent(multiPart);
    

    Thanks for the help!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a tomcat based application that needs to submit a form capable of
I have a application that is deployed on tomcat container. I'm running the jmeter
I have an application that is successfully deploying on tomcat, which I must migrate
I have an application that usually is hosted on a Windows 2003 Apache Tomcat
I have a web application made with Spring that runs on Tomcat. On the
I have a web application running on tomcat at port 8080. The application needs
I have a web application that executes on tomcat 6. I have a MysqlDb
I have a web application on tomcat. The application needs two SAXParserFactory implements: one
I have several files comprising a tomcat web application that I need to import
i have tomcat server that holds web application i like to be able to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.