Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

iam unable to send multiple attachments with a mail using JavaMail?

843830Nov 19 2005 — edited Apr 2 2008
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.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 30 2008
Added on Nov 19 2005
6 comments
397 views