dcsimg
Modify A Mail Body
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Andrew_Cao
Posted On:   Wednesday, October 29, 2003 08:09 PM

Hi I have following code: FileInputStream is = new FileInputStream("source"); MimeMessage msg = new MimeMessage((Session)null, is); MimeMultipart mp = (MimeMultipart)msg.getContent(); MimeBodyPart part = (MimeBodyPart)mp.getBodyPart(0); part.addHeader("NewHeader", "NewValue"); msg.addHeader("Header1", "Value1"); msg.saveChanges(); When I write msg out, I see Header1 has been added to msg but NOT NewHeader. Is there a way to modify a body part of a multipart email? Thanks    More>>

Hi

I have following code:

			
FileInputStream is = new FileInputStream("source");
MimeMessage msg = new MimeMessage((Session)null, is);
MimeMultipart mp = (MimeMultipart)msg.getContent();
MimeBodyPart part = (MimeBodyPart)mp.getBodyPart(0);
part.addHeader("NewHeader", "NewValue");
msg.addHeader("Header1", "Value1");
msg.saveChanges();


When I write msg out, I see Header1 has been

added to msg but NOT NewHeader.



Is there a way to modify a body part of a

multipart email?

Thanks

   <<Less

Re: Modify A Mail Body

Posted By:   shiladitya_sircar  
Posted On:   Thursday, November 6, 2003 07:19 AM

You are adding in a new header .. but there is nothing that extract the bodypart and modifies it.

The Example below modifies bodypart. Add recipients to the message body


MimeMessage newmsg = new MimeMessage((MimeMessage) msg);
Object obj = newmsg.getContent();
MimeMultipart mmp = (MimeMultipart) obj;
BodyPart bp = (BodyPart) mmp.getBodyPart(0);
Object original_content = bp.getContent();
String addressString = "
";
for (int j = 0; j < allRecipients.length; j++) {
InternetAddress recip =(InternetAddress) allRecipients[j];
addressString += "Invited: " + recip.toString()+"
";
}
original_content = original_content + addressString;
Object newobj = original_content;
bp.setContent(newobj,bp.getContentType());
mmp.removeBodyPart(0);
mmp.addBodyPart(bp,0);
newmsg.setContent(mmp);
newmsg.saveChanges();

About | Sitemap | Contact