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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:53:25+00:00 2026-05-22T14:53:25+00:00

Are there any packages available that will efficiently send emails with large attachments (each

  • 0

Are there any packages available that will efficiently send emails with large attachments (each file is capped at 10mb, but could include multiple files). If not, any suggestions on an appropriate design that wouldn’t result in out of memory exceptions causing issues across applications deployed on the same server?

Files are delivered to the application server by ftp. Once transmission is complete, a web service is invoked (metadata for the transaction). Based on business rules, this service may need need to email the files.

My initial thoughts were a putting the request on a message queue (so the service can return immediately), and having a synchronized method process the request (so multiple requests at or around the same time won’t blow up the heap).


updating with code

messageBodyPart = new MimeBodyPart();
FileDataSource fileDataSource =new FileDataSource("locationTo.big.file");
messageBodyPart.setDataHandler(new DataHandler(fileDataSource));
messageBodyPart.setFileName("big.file");
multipart.addBodyPart(messageBodyPart);
<rinse..repeat>

message.setContent(multipart);

Transport.send(msg);

If I attach 5 10mb attachments, 50mb won’t be eaten up by the heap all at once?

  • 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-22T14:53:26+00:00Added an answer on May 22, 2026 at 2:53 pm

    Why not use an Executor, with a thread pool growing/shrinking within reason. Each task submitted is a Runnable or Callable. The Task sends via JavaMail, which DOES not take much memory if you implement your own DataSource implementations for the attachments and/or message body. (I am assuming you have have InputStream acccess to the attachments)

    Adding code as sample (note this code was written many years ago, and is pretty bad for many reasons. But it shows the concept)

    public static void sendMailAndThrowException(SMTPParams sparams,String  subject, DataSource msgTextSource,DataSource[] fids,boolean debug) throws MessagingException {
        Session session=getMailSession(sparams);
    PrintStream f = null;
    if (debug) {            
            f= getPrintStream();        
    } 
    // null is System.out by javamail api
    session.setDebug(debug);
    session.setDebugOut(f);     
    
    try
    {
        // create a message
        MimeMessage msg = new MimeMessage(session);
        msg.setFrom(new InternetAddress(sparams.getFrom()));
    
        // Recipients are comma delimitted
        String to_list[] = sparams.getRecipients().split(",");
        InternetAddress[] address = new InternetAddress[to_list.length];
        for( int i=0; i< to_list.length; i++)
        {
            // MJB: remove extraneous spaces, sanity check
            String temp = to_list[i].trim();
            if (temp.length()>0) {
                address[i] = new InternetAddress(to_list[i].trim());
            }
        }
        // Addresses are always TO, never CC  or BCC in this library
        msg.setRecipients(Message.RecipientType.TO, address);
            if ((msg.getAllRecipients() == null) || (msg.getAllRecipients().length==0)) {
                throw new MessagingException("No valid recipients");
            }
    
        // Set the subject
        msg.setSubject(subject,"UTF-8");
    
        // create the Multipart and add its parts to it
        Multipart mp = new MimeMultipart();
    
    
        if (msgTextSource != null) {
            // create and fill the first message part
            MimeBodyPart mbp1 = new MimeBodyPart();
            mbp1.setDataHandler(new DataHandler(msgTextSource));
            mp.addBodyPart(mbp1);
        }
    
        if( fids != null)
        {
            for (int i=0;i<fids.length;i++) {
                //  create the second message part
                if (fids[i]==null) continue;
                MimeBodyPart mbp2 = new MimeBodyPart();
                //  attach the file to the message
                mbp2.setDataHandler(new DataHandler(fids[i]));
                mbp2.setFileName(fids[i].getName());
                mp.addBodyPart(mbp2);
            }
        }
    
        // add the Multipart to the message
        msg.setContent(mp);
    
        // set the Date: header
        msg.setSentDate(new java.util.Date());
    
        // Connect to SMTP server
        smtpSend(session, msg, sparams);
    
    }
    
    catch (MessagingException mex)
    {
        throw mex;
    } finally {
        closeDebug(f);
    }
    
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Are there any packages that can take a directory full of source code (Objective-C
Are there any free tools or software packages that offer functionality similar to MS
Are there any open source (or I guess commercial) packages that you can plug
I was wondering if there are any packages available out there to make CSS3
Are there any software packages available for hosting Mercurial repositories on my own server
Are there any scientific packages for Lua comparable to Scipy?
Are there any other packages for doing Venn diagrams in R besides the limma
Are there any R packages for the calculation of Kendall's tau-b and tau-c, and
Is there any way to check whether a file is locked without using a
Is there any free or commercial component written in .NET (no COM interop) that

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.