Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Emailing multiple attachments

Status
Not open for further replies.

amethystct

Programmer
Jan 26, 2004
21
FR
I have a delivery sheet being emailed. The first page is dynamic. That attaches fine. The second page has to be emailed with the first page also an attachment. They're both pdf files. When I try to attach it I get no errors but it creates an empty file. I don't want to recreate the second file, I just want to attach it.
Do I need to loop through the second file and attach it the same way with another setContent and will that replace the first file with the second?

Message msg = MimeMessageUtils.createMessage();

MimeMultipart mp = new MimeMultipart();
MimeBodyPart text = new MimeBodyPart();
text.setDisposition(Part.INLINE);
text.setContent(pEmailBody, "text/plain");
mp.addBodyPart(text);

String attachmentName = null;
MimeBodyPart file_part = null;
for (int ctr = 0; ctr < attachments.length; ctr++) {
file_part = new MimeBodyPart(new InternetHeaders(), attachments[ctr].getAttachment());
System.out.println("Size of attachment is: " + attachments[ctr].getAttachment().length);
file_part.setDisposition(Part.ATTACHMENT);
file_part.setHeader("Content-Transfer-Encoding", contentEncoding);
attachmentName = attachments[ctr].getFileName();
if (attachmentName != null) {
file_part.setFileName(attachmentName);
file_part.setDescription(attachmentName);
}
mp.addBodyPart(file_part);
}
msg.setContent(mp);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top