How to send Email with 2 or many attached files

Posted on 2006-04-12
Last Modified: 2010-04-01
Hi Experts

How can i send email  with 2 files attached with it from my JSP Page using JavaMail.

Question by:massrico
    LVL 11

    Expert Comment

    LVL 11

    Accepted Solution

    for sending multiple files the following may help
    File[] attachments=new File{"file1" ,"file2","file3"}

    for( int i = 0; i < attachments.length; i++ )
        messageBody = new MimeBodyPart();

        FileDataSource fileDataSource =new FileDataSource(attachments[i]);
        messageBody.setDataHandler(new DataHandler(fileDataSource));
    LVL 23

    Expert Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    ADCs have gained traction within the last decade, largely due to increased demand for legacy load balancing appliances to handle more advanced application delivery requirements and improve application performance.
    This paper addresses the security of Sennheiser DECT Contact Center and Office (CC&O) headsets. It describes the DECT security chain comprised of “Pairing”, “Per Call Authentication” and “Encryption”, which are all part of the standard DECT protocol.
    This video discusses moving either the default database or any database to a new volume.
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now