Iam unable to attach multiple files to a email using javamail?

Hai to all,
Sorry that snipnet is for only one attachment ,
iam sending my topic again,plese go through it.
Iam unable to send multiple attachments with a email,see
iam have succeeded in sending one attachment with a email.
when iam tring to add two or more attachments to a mail,
it is giving a Exception like this:
javax.mail.MessagingException: IOException while sending message;
nested exception is:
java.io.IOException: No content
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:577)
at javax.mail.Transport.send0(Transport.java:151)
at javax.mail.Transport.send(Transport.java:80)
at AttachFilesModified.sendMail(AttachFilesModified.java:185)
at AttachFilesModified.main(AttachFilesModified.java:43)
this is my code snipnet:
BodyPart messageBodyPart = new MimeBodyPart();
Multipart multipart = new MimeMultipart();
if(body != null)
messageBodyPart.setText(body);
multipart.addBodyPart(messageBodyPart);
/*if(attachments != null)
for(int i = 0; i < attachments.length; i++)
String filename="D:\\nagaraju\\apachi\\axis-bin-1_3.zip";
//String s[]=filename.split("\\");
//System.out.println(s);
//String s1=s[1];
//String filename1=s[s.length-1];
messageBodyPart = new MimeBodyPart();
DataSource source = new FileDataSource(filename);
messageBodyPart.setDataHandler(new DataHandler(source));
messageBodyPart.setFileName(filename);
multipart.addBodyPart(messageBodyPart);
//second file attaching
String filename1="C:\\nagadoc.txt";
BodyPart messageBodyPart1=new MimeBodyPart();
DataSource source1=new FileDataSource(filename1);
messageBodyPart.setDataHandler(new DataHandler(source1));
messageBodyPart.setFileName(filename1);
multipart.addBodyPart(messageBodyPart1);
mess.setContent(multipart);
Address[] allRecips = mess.getAllRecipients();
if(toStdOut)
System.out.println("done.");
//System.out.println("Sending message (\"" + mess.getSubject().substring(0,10) + "...\") to :");
System.out.println("Sending message................");
for(int i = 0; i < allRecips.length; i++)
System.out.print(allRecips + ";");
System.out.println("...");
Transport.send(mess);
if(toStdOut)
System.out.println("done.");
return 0;
What's wrng with that code snipnet?
Nagaraju G.

This works fine with me, try it or compare it if you want.
public void sendEmail( String from, String to,
String subject, String body) {
fMailServerConfig.put("mail.smtp.host", " <<mail server>>");
Session session = Session.getDefaultInstance( fMailServerConfig, null );
MimeMessage message = new MimeMessage( session );
try {
message.setFrom(new InternetAddress(from));
message.setRecipient(Message.RecipientType.TO,
new InternetAddress(to));
message.setSubject( subject);
message.setText( body);
//Adds Attechment:
Multipart multipart = new MimeMultipart();
BodyPart messageBodyPart = new MimeBodyPart();
messageBodyPart.setText("Here are my attachments");
multipart.addBodyPart(messageBodyPart);
messageBodyPart = new MimeBodyPart();
//first attachment
DataSource source = new FileDataSource("C:\\img1.jpg");
messageBodyPart.setDataHandler(new DataHandler(source));
messageBodyPart.setFileName("C:\\Telnor1.jpg");
multipart.addBodyPart(messageBodyPart);
//Second attachment
DataSource source2 = new FileDataSource("C:\\img2.jpg");
messageBodyPart.setDataHandler(new DataHandler(source2));
messageBodyPart.setFileName("C:\\Telnor2.jpg");
multipart.addBodyPart(messageBodyPart);
//etc...
message.setContent(multipart);
Transport.send( message );
}catch (MessagingException e){
System.err.println("Cant send mail. " + e);
The error on your code might be:
BodyPart messageBodyPart1=new MimeBodyPart();
DataSource source1=new FileDataSource(filename1);
messageBodyPart.setDataHandler(new DataHandler(source1));
messageBodyPart.setFileName(filename1);
multipart.addBodyPart(messageBodyPart1);
You don't need to create a new BodyPart, and apart from that you'r seting values on "messageBodyPart" but adding "messageBodyPart1" to your multipart :P
Well see u and have a good one!
p.s. i know it's a little late from the day you posted, but at least it might help somebody else :D .

Similar Messages

  • Iam unable to send multiple attachments with a mail using JavaMail?

    Hai to all,
    Iam unable to send multiple attachments with a email,see
    iam have succeeded in sending one attachment with a email.
    when iam tring to add two or more attachments to a mail,
    it is giving a Exception like this:
    javax.mail.MessagingException: IOException while sending message;
    nested exception is:
    java.io.IOException: No content
    at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:577)
    at javax.mail.Transport.send0(Transport.java:151)
    at javax.mail.Transport.send(Transport.java:80)
    at AttachFilesModified.sendMail(AttachFilesModified.java:185)
    at AttachFilesModified.main(AttachFilesModified.java:43)
    this is my code snipnet:
    BodyPart messageBodyPart = new MimeBodyPart();
    Multipart multipart = new MimeMultipart();
    if(body != null)
    messageBodyPart.setText(body);
    multipart.addBodyPart(messageBodyPart);
    /*if(attachments != null)
    for(int i = 0; i < attachments.length; i++)
    String filename="D:\\nagaraju\\apachi\\axis-bin-1_3.zip";
         //String s[]=filename.split("\\");
         //System.out.println(s);     
              //String s1=s[1];
              //String filename1=s[s.length-1];
    messageBodyPart = new MimeBodyPart();
    DataSource source = new FileDataSource(filename);
         messageBodyPart.setDataHandler(new DataHandler(source));
    messageBodyPart.setFileName(filename);
    multipart.addBodyPart(messageBodyPart);
         //second file attaching
         /*String filename1="C:\\nagadoc.txt";
         BodyPart messageBodyPart1=new MimeBodyPart();
         DataSource source1=new FileDataSource(filename1);
         messageBodyPart.setDataHandler(new DataHandler(source1));
         messageBodyPart.setFileName(filename1);
         multipart.addBodyPart(messageBodyPart1);
    mess.setContent(multipart);
    Address[] allRecips = mess.getAllRecipients();
    if(toStdOut)
    System.out.println("done.");
    //System.out.println("Sending message (\"" + mess.getSubject().substring(0,10) + "...\") to :");
    System.out.println("Sending message................");
    for(int i = 0; i < allRecips.length; i++)
    System.out.print(allRecips[i] + ";");
    System.out.println("...");
    Transport.send(mess);
    if(toStdOut)
    System.out.println("done.");
    return 0;
    What's wrng with that code snipnet?
    Nagaraju G.

    This works fine with me, try it or compare it if you want.
    public void sendEmail( String from, String to,
    String subject, String body) {
    fMailServerConfig.put("mail.smtp.host", " <<mail server>>");
    Session session = Session.getDefaultInstance( fMailServerConfig, null );
    MimeMessage message = new MimeMessage( session );
    try {
    message.setFrom(new InternetAddress(from));
    message.setRecipient(Message.RecipientType.TO,
    new InternetAddress(to));
    message.setSubject( subject);
    message.setText( body);
    //Adds Attechment:
    Multipart multipart = new MimeMultipart();
    BodyPart messageBodyPart = new MimeBodyPart();
    messageBodyPart.setText("Here are my attachments");
    multipart.addBodyPart(messageBodyPart);
    messageBodyPart = new MimeBodyPart();
    //first attachment
    DataSource source = new FileDataSource("C:\\img1.jpg");
    messageBodyPart.setDataHandler(new DataHandler(source));
    messageBodyPart.setFileName("C:\\Telnor1.jpg");
    multipart.addBodyPart(messageBodyPart);
    //Second attachment
    DataSource source2 = new FileDataSource("C:\\img2.jpg");
    messageBodyPart.setDataHandler(new DataHandler(source2));
    messageBodyPart.setFileName("C:\\Telnor2.jpg");
    multipart.addBodyPart(messageBodyPart);
    //etc...
    message.setContent(multipart);
    Transport.send( message );
    }catch (MessagingException e){
    System.err.println("Cant send mail. " + e);
    The error on your code might be:
    BodyPart messageBodyPart1=new MimeBodyPart();
    DataSource source1=new FileDataSource(filename1);
    messageBodyPart.setDataHandler(new DataHandler(source1));
    messageBodyPart.setFileName(filename1);
    multipart.addBodyPart(messageBodyPart1);
    You don't need to create a new BodyPart, and apart from that you'r seting values on "messageBodyPart" but adding "messageBodyPart1" to your multipart :P
    Well see u and have a good one!
    p.s. i know it's a little late from the day you posted, but at least it might help somebody else :D .

  • Unable to attach multiple files to an email in Safari using Macbook Pro 2011

    Is anyone else having this issue?  Safari won't let me select multiple files to attach to an email.  I can attach more than one file, but I have to attach them one at a time.  Is there a setting I need to change or something??

    I am having exactly the same issue as debsdesign.  The email I am using is yahoo.  I've tried both Safari and Firefox and it makes no difference.  I am using Mac OS X Lion 10.7.5.
    So to reiterate the problem - I want to attach multiple files at once to an email message I want to send.  I have tried to do the following:
    1. Select 'Attach file" in my email message
    2. In 'Finder' I have found a list of files I want to attach
    3. I can only select one file at a time and "choose" them individually - I have 16 files.  I have tried holding down the SHIFT key and selecting the last file in the list.  I have also tried holding down the COMMAND key and selecting each file in turn.  Nothing works!
    Is there a way to do this on a Mac??
    Many thanks

  • All of a sudden I am unable to attach a file to my email without compressing

    All of a sudden I am unable to attach a file to my email without compressing. The email will show no attached file and then freezes and I am unable to add any content to body of email or change any of the content. I have to just delete the email and start over. If I zip the file it will show up in the body of the email and I am able to add content and send the email. This just stared happening, I had not changed any preferences or anything so I have no idea what happened.

    Want to explain - makes no sense  since they share the exact same library
    It actually that details are critical since we know nothing about your configuration or situation except what you choose to share with us  --  including what "everything you can think of" is
    LN

  • Unable to attach a file to the email

    I am trying to attach a file using mail.app. When I click on attach(paper clip icon) then I am unable to traverse down to a sub-directory and to a file, instead mail.app attach the entire directory as an attachment. Is this a limitation with OS X? Again I tried the same with Sparrow to no avail.
    Only way is to open a finder window and drag file to the email message.
    Any ideas or help would be greatly appreciated?
    Thanks,
    Paddy

    Please read this whole message before doing anything.
    This procedure is a diagnostic test. It’s unlikely to solve your problem. Don’t be disappointed when you find that nothing has changed after you complete it.
    The purpose of this exercise is to determine whether the problem is caused by third-party system modifications that load automatically at startup or login. Disconnect all wired peripherals except those needed for the test, and remove all aftermarket expansion cards. Boot in safe mode* and log in to the account with the problem. The instructions provided by Apple are as follows:
    Be sure your Mac is shut down.
    Press the power button.
    Immediately after you hear the startup tone, hold the Shift key. The Shift key should be held as soon as possible after the startup tone, but not before the tone.
    Release the Shift key when you see the gray Apple icon and the progress indicator (looks like a spinning gear).
    *Note: If FileVault is enabled under Mac OS X 10.7 or later, you can’t boot in safe mode.
    Safe mode is much slower to boot and run than normal, and some things won’t work at all, including wireless networking on certain Macs.
    The login screen appears even if you usually log in automatically. You must know your login password in order to log in. If you’ve forgotten the password, you will need to reset it before you begin.
    Test while in safe mode. Same problem(s)?
    After testing, reboot as usual (i.e., not in safe mode) and verify that you still have the problem. Post the results of the test.

  • I am unable to attach PDFs to Hotmail/Outlook email using my FF browser today. Never had issue before today.

    1. I am unable to attach pdfs today in Outlook/Hotmail email using my Firefox browser (27.0.1). I keep getting an error message that says, "The file is not a picture and can't be inserted inline." I do not understand why I keep getting this error message. I am not attempting to insert an image. I am selecting to Insert Files as Attachments from the drop down menu.
    No matter how many times I attempt to attach various pdfs to my emails today using Firefox as my browser, I keep getting this same error message. I have cleared the cache, cleared all cookies, cleared all history, signed out of my Hotmail/Outlook account, signed back in, restarted computer, etc., to no avail. Same problem.
    2. I switched to my Safari browser, and have no problem attaching pdfs in my Hotmail/Outlook email account. The pdfs are attaching perfectly as usual. My emails are being sent normally with the attachments. The attached pdfs are being received and are opening perfectly as intended.
    3. Why am I unable to attach files with Firefox today? Firefox is my browser of choice and I have used it with my Hotmail/Outlook email account without any problems, till today. Please help me! Thank you!

    Thank you jscher2000. Yes my PDFs do contain the .pdf extension. I tried your excellent idea to utilize the drag and drop method, but I still get the same error message with PDFs. I have no problem attaching photos or Word documents with either method; just PDFs.
    For further diagnostics, I started composing my email in Safari, attached all my pdfs and saved my email as a Draft.  I then went to Firefox, opened the draft to continue working on it, and voila!  There are all the pdfs I attached previously while in Safari.  I was able to send the email with attachments through Firefox with no issues. The attachments went through and were able to be opened.
    I am mystified, as Firefox has been trouble-free with my email account, and I have never had this particular issue till today. I made no changes to anything else on my computer, but I did notice very late last night that Outlook had one of those typical messages at the top of my Inbox to refresh my browser since Outlook had been updated. I refreshed and shut down for the night, and when I rebooted this morning that is when I discovered this brand new glitch with attachments. I'm assuming this has something to do their last update.

  • I am unable to attach a file to an email

    I have been able to find the file to be attached, highlight it and click open but with no result.

    Hello, Firefox's pop-up blocker may have prevented the file upload window from opening. Please try adding Gmail to your list of allowed sites by following the steps below:
    # Click on the 3-bar menu button and choose '''Options'''.
    # Select the '''Content panel'''.
    # Click on the '''Exceptions''' button next to Block pop-up windows.
    # In the Allowed Sites window, type in mail.google.com in the address field, then click '''Allow''' to add it to the list.
    # Click '''Close''' to finish.
    '''EDIT: try one more time before the above suggestion.'''
    thank you

  • How can I attach multiple photos to an email using IOS 8.1.1

    I am trying to avoid having to attach one photo at a time when emailing a group.

    One option that you have is to go to the Photos App and go to your Camera Roll or where you have the pictures you want to send, then click on the select option at the top right side and select all the pictures you want to email.
    Once you selected everything then click on the share button at the bottom and do the following depending on the number of photos:
    - If you want to send 5 or less then you can select the mail option and this will create a draft with your pictures and then you can just add the address
    - If you  to send more than 5 then you can select copy, then go to the mail app, create a new email, press and hold on the text section and then select paste, all your pictures will be copied and then just add the address you need.
    Hope this helps.

  • If I attach a file to an email using Firefox it is received jumbled up but not so if I send the same file with Safari

    By jumbled I mean letters, symbols, punctuation marks etc. Total nonsense. If I scan a document then e.mail it using Firefox as my browser, when opened it is a jumble. If I take that same scanned document and e.mail it out using Safari it opens up completely legible. This is new stuff only since today. Heretofore Firefox has been terrific.

    In Mail's menu, go to Edit > Attachments > Always send windows-friendly attachments and click it.
    Attachments may appear embedded in the email on your end, but should appear as standard Windows attachments on the recipient's end.

  • Why can't I attach any files to my email

    I downloaded firefox 5 and yesterday, and now I am unable to attach any files to my email.
    I create artwork and can not attach any illustrator or photoshop files. Why?

    I just solved my own problem a few minutes ago. There was a little switch on the bottom of the Traveldrive. Locked or unlocked (the little lock symbols were so small I couldn't read them without a magnifying glass.
    Thank you for responding, sorry to trouble you.

  • Since latest upgrade to 7.0.1, I cannot attach a file to my emails

    Since the last Firefox upgrade, now 7.0.1, I cannot attach files to my emails using MobileMe Mail. I us an iMac, OS X Version 10.6.8

    Hi Swarnava
    I upgraded to Firefox 8.0 but, regrettably I am still unable to attach any files to my emails. Mail on my iMac will however accept the atachments.

  • I suddenly cannot attach any file to an email whilst using Firefox 5.

    My preferred browser is Firefox 5, which I have been using trouble-free until now. All of the sudden, I am unable to attach any file to an email. I simply get a file loading attempt that never times out. At first I thought it was a Yahoo problem, but my work email server will not add attachments either. I downloaded Google Chrome just now as a test, and still can't add attachments. Might this be a Windows problem? Anyone run into this? Thank you. I am my own IT department and it is sad... Katherine

    Try clearing your browser cache.
    Tools > Clear Recent History... - hit Details and make sure only Cache is selected, then select Everything and hit the Clear Now button.

  • I am trying to attach multiple photos to an email from my ipad 2. I can see how to do it from the camera and camera roll option,but not from the photos program. What am I missing? Thanx so much!

    I am trying to attach multiple photos to an email using ipad 2. I can see how to do it using the camera and camera roll ap...
    But not using the photos ap..which is where the photos are. Any help would be appreciated.!

    In an album in Photos touch the Edit button and then touch the desired photos (up to 5). A blue check appears in each selected photo. Next touch the Share button at the upper left and select Mail. This starts a email with the photos attached.

  • How to attach multiple file in one mail

    Hi,
    I've problems with sending multiple files via Gmail account (Ipad version)  When sending the photo or video, I've to just click the photo and choose send to mail one by one. Any simpler way?  Sometimes i did sent both mpg and jpg but the reciepient didn't see any attachment too
    Anyone can help advise how to attach different file (doc, video, photo) in one mail will be a lot appreciated. Thank you so much

    You can attach multiple pictures to an email on an ipad2. Don't know about original iPad.
    Choose a photo or take a screen shot (hold down home button and button next to volume control at same time--screen shot now will appear in photos).
    Go to photos and edit your picture or screen shot, save it, then hold down on the image and copy it.
    Go to mail, create a new mail and paste it in.
    Save you mail as a draft.
    Go back to photos and select a different photo, copy it, and return to your draft, and paste it in. Repeat if you need to add more.
    Anything that you can take a screen shot or have an photo of can be pasted in one at a time into that draft email.
    If mail gets uncooperative, during this process, then double click on home button and quit multitasking mail, then open up mail again and send your draft. Uncooperative means gets frozen.

  • Ipad 4: how do I attach multiple file types to an email?

    Hello,
    I have seen multiple threads on this topic saying you can only do attachments in an email (other than photos or videos) by going to the app that holds the file and emailing it from there (ex: go to adobe reader or ibooks to email a PDF). This work around seemed sufficient for some people but I have need to attach a JPG, PDF and .doc to a single email. How do I do this within the ipad's built in email app? Is this impossible and if so are there other free email apps that someone can reccmmend?
    I find the ability to only email files from within its parent app to be cumbersome and not in keeping with Apple's style of making one's life easier and more efficient. In fact this seems woefully backward and goes back to the early days of computing. I get it that emailing from within a particular app is necessary but so is the ability to attach multiple file types from within the email app. :-(
    So frustrated!!

    The GoodReader App can manage files and create emails consisting of multiple files types.
    See here: https://itunes.apple.com/us/app/goodreader-4/id777310222?mt=8

Maybe you are looking for

  • Webserver on DMZ cannot send email via php script using SMTP (cisco firewall pix 515e)

    Hello, I have two web servers that are sitting in a DMZ behind a Cisco Firewall PIX 515e. The webservers appear to be configured correctly as our website and FTP website are up. On two of our main website, we have two contact forms that use a simple

  • PowerShell runs on Windows 8.1 PS v4.0, but fails on 2008R2 PS v2.0

    I developed a PS script to run on my server to discover if certain files exist*. I developed the code on Win 8.1 64-bit which has PS version 4.0 installed. It works perfectly. I copied the files to my Win 2008R2 SP1 64-bit server with PS version 2.0

  • Ios 8 having lots of problem in iphone 5c

    today i just updated my iphone 5c to ios8.. after the update i checked my iphone for all the new features to my suprise it dosent have the audio message in Message app like shown in the features.. on top of that if u get any notifications u cannot ev

  • How to pass bind variable into oracle reports 6i - Parameter form

    Hello All, I want to pass bind variable into Oracle Reports 6I - Parameters. I have tried out that but got the below error :- rep-0781 : Bind variables are not allowed in the select statement Kindly help me is there any option which allow me to pass

  • CIV 5 Wont Open from Steam EXC_BAD_ACCESS(SIGSEGV)

    Please help! Don't know what is causing this Process:         Civilization V [345] Path:            /Users/maxjackson/Library/Application Support/Steam/SteamApps/common/Sid Meier's Civilization V/Civilization V.app/Contents/MacOS/Civilization V Ident