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 8781351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:16:44+00:00 2026-06-13T20:16:44+00:00

I have a web-app which I use which expects a specific boundary string like

  • 0

I have a web-app which I use which expects a specific boundary string like (“company mime boundary”).

I did not find a way to override the default behavior of MimeMultipart, when I do

Multipart mp = new MimeMultipart();

A unique boundary string is always created by the constructor and I want to override this behavior to have my own boundary string, but unable to do so as I did not find any API.

Even if I set it in content-type, it does not work and creates a unique boundary string always as the MimeMultipart is creating a default one.

mimeMsg.setHeader("Content-Type","multipart/mixed;boundary="company mime boundary");

Can anyone please suggest/help me on this.

How to override this default behavior ?

  • 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-13T20:16:47+00:00Added an answer on June 13, 2026 at 8:16 pm

    From javax.mail.Multipart :

    The mail.mime.multipart.ignoreexistingboundaryparameter System property may be set to true to cause any boundary to be ignored and instead search for a boundary line in the message

    Try setting this property to true and then add your own using

    mimeMsg.setHeader("Content-Type","");
    

    I have not implemented it, but I am confident it can work

    update

    Try sub-classing the MimeMultipart class and overwrite the getBoundaryMethod(). See some sample code below:

    import javax.activation.DataSource;
    import javax.mail.MessagingException;
    import javax.mail.internet.ContentType;
    import javax.mail.internet.MimeMultipart;
    public class MyMimeMultyPart extends MimeMultipart {
        /**
         * DataSource that provides our InputStream.
         */
        protected DataSource ds;
    
        /**
         * Indicates if the data has been parsed.
         */
        protected boolean parsed = true;
    
        private ContentType type;
    
        public MyMimeMultyPart(DataSource dataSource) throws MessagingException {
            super(dataSource);
        }
    
        public MyMimeMultyPart(String subtype) {
            type = new ContentType("multipart", subtype, null);
            type.setParameter("boundary", getBoundary());
            contentType = type.toString();
        }
    
        public MyMimeMultyPart() {
            super();
        }
    
        private static int part;
    
        private synchronized static String getBoundary() {
            int i;
            synchronized (MimeMultipart.class) {
                i = part++;
            }
            StringBuffer buf = new StringBuffer(64);
            buf.append("----=_Part_").append(i).append('_').append((new Object()).hashCode()).append('.').append(System.currentTimeMillis());
            return buf.toString();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my web app I have a line which looks like this: small textbox
I have a web app of which I would like to create a mobile
I have written a web app in PHP which makes use of Ajax requests
I have a web app which has standard things for learning based app like
I have a simple web-app in which I use struts and xslt transformation. In
I have a web app which lets the user select the excel spreadsheet and
I have a Flash web app which displays user submitted PNG files. Files are
I have a Silverlight web app which uses ASP.net Website administration tool for user
Have an ASP.net web app which works fine for a few days, but then
The thing I have a web app (asp.net) which needs to have a feed.

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.