Multiple Attatchments
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   kdhawan_dhawan
Posted On:   Tuesday, November 13, 2001 02:07 AM

I am unable to attatch multiple files to the text body of the message.The code which i hv written attatches only on file.I thought of running it in a loop so that it attatches multiple file but only the last one gets attatched.The goes as.. Message message = new MimeMessage(session); message.setFrom(new InternetAddress(from)); message.addRecipient(Message.RecipientType.TO, new InternetAddress(to)); message.setSubject("Hello JavaMail Attachment"); File fileobj = new File("c:\temp\8lg66bl5y118"); String filelist[] = fileobj.list(); // Create the message part BodyPart messageBodyPart = new MimeBodyPart(); // Fill the message messageBo   More>>

I am unable to attatch multiple files to the text body of the message.The code which i hv written attatches only on file.I thought of running it in a loop so that it attatches multiple file but only the last one gets attatched.The goes as..

			
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO,
new InternetAddress(to));
message.setSubject("Hello JavaMail Attachment");

File fileobj = new File("c:\temp\8lg66bl5y118");
String filelist[] = fileobj.list();

// Create the message part
BodyPart messageBodyPart = new MimeBodyPart();

// Fill the message
messageBodyPart.setText("Here's the file");

// Create a Multipart
Multipart multipart = new MimeMultipart();

// Add part one
multipart.addBodyPart(messageBodyPart);
for(int i=0;i
{
System.out.println(filelist[i]);
// Create second body part
messageBodyPart = new MimeBodyPart();

DataSource source = new FileDataSource("c:\temp\8lg66bl5y118\"+filelist[i]);

messageBodyPart.setDataHandler(new DataHandler(source));

messageBodyPart.setFileName(filelist[i]);
multipart.addBodyPart(messageBodyPart);
}
message.setContent(multipart);
Transport.send(message);

pls advice the solution to this.
thanx    <<Less

Re: Multiple Attatchments

Posted By:   Anonymous  
Posted On:   Tuesday, November 13, 2001 04:07 PM

As a source for more information, try inserting:


multipart.writeTo(System.out);



message.setContent(multipart);

Transport.send(message);


... to see if the problem is that only one part is being added... Maybe the reader is only reading one part and skipping the others?

Make sure the DataSource is not null.

Good luck!

-w
About | Sitemap | Contact