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

  • Home
  • SEARCH
  • 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 3698406
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:58:39+00:00 2026-05-19T04:58:39+00:00

How do you create email message that contains text and HTML version for the

  • 0

How do you create email message that contains text and HTML version for the same content?

Of course I would like to know how to setup the freemarker template or the header of the message that will be send.

When I look on the source of message multi-part message in MIME format that I receive in inbox every once in while this is what is in there:

This is a multi-part message in MIME format.

------=_NextPart_000_B10D_01CBAAA8.F29DB300
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

...Text here...

------=_NextPart_000_B10D_01CBAAA8.F29DB300
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<html><body> html code here ... </body></html>
  • 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-05-19T04:58:39+00:00Added an answer on May 19, 2026 at 4:58 am

    If you spot any inconsistencies please let me know. I had to extract this from pretty complex object so that’s why this looks like it does.

    //some important imports
    import freemarker.template.Template;
    import org.springframework.mail.javamail.*;
    import org.springframework.context.*;
    import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;
    import javax.mail.internet.MimeMessage;
    
    private JavaMailSender mailSender;
    private MessageSource messageSource;
    private ExecutorService executor = Executors.newFixedThreadPool(50);
    
    MimeMessagePreparator preparator = new MimeMessagePreparator() {
        public void prepare(MimeMessage mimeMessage) throws Exception {
            MimeMessageHelper message = new MimeMessageHelper(mimeMessage);
    
                message.setFrom(from);
                message.setTo(recipient);
                message.setSubject(subject);
    
                // Now the message body.
                Multipart mp = new MimeMultipart();
    
                BodyPart textPart = new MimeBodyPart();
                Template textTemplate = freemarkerConfig.getConfiguration().getTemplate(textEmailTemplate); // "/WEB-INF/emailText/*.ftl"
                final StringWriter textWriter = new StringWriter();
                textEmailTemplate.process(modelMap, textWriter);
                textPart.setText(textWriter.toString()); // sets type to "text/plain"
    
    
                BodyPart pixPart = new MimeBodyPart();
                Template pixTemplate = freemarkerConfig.getConfiguration().getTemplate(pixEmailTemplate); // "/WEB-INF/emailPix/*.ftl"
                final StringWriter pixWriter = new StringWriter();
                textEmailTemplate.process(modelMap, pixWriter);
                pixPart.setContent(pixWriter.toString(), "text/html");
    
                // Collect the Parts into the MultiPart
                mp.addBodyPart(textPart);
                mp.addBodyPart(pixPart);
                // Put the MultiPart into the Message
                 message.setContent(mp);                  
    
         }
    };
    
    executor.submit(new SendMail(preparator));
    
    class SendMail extends Thread {
        MimeMessagePreparator preparator;
    
        SendMail(MimeMessagePreparator preparator) {
            this.preparator = preparator;
        }
    
        public void run() {
            mailSender.send(preparator);
          }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a web application. A user will create an email message that
I'm programming in PHP and would like to create web pages which have email
I need to create an email in C# that is sent to a blackberry
I have a partial that contains a form: <% form_for :message, :url => {
How can I create an array of email addresses contained within a block of
Create a flat text file in c++ around 50 - 100 MB with the
Create a file called Valid[File].txt and stick some text in it. Start powershell and
I am trying to set up an email function that will email the last
I have a bunch of legacy code for encoding raw emails that contains a
I would like to get some of your ideas about resource name / categorizing

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.