| Author |
sending email attachment with Struts?
|
Mitch Abaza
Greenhorn
Joined: Jul 21, 2004
Posts: 6
|
|
I'm looking for sample code that shows how to add a FormFile object as an attachment to a javax.mail.internet.MimeMessage object. All examples I have seen are using servlets and a File object, which I can't really use. I know I can derive an InputStream from FormFile.getInputStream, and that the MimeBodyPart class takes an InputStream as a constructor, but I can't get the header information to make sense. Whenever I send the email, the attachment doesn't show up. Here's some pseudo code that I have so far (attachment is a FormFile object): ========================================== Message message = new MimeMessage( session ); message.setFrom( new InternetAddress( address, name ) ); message.setRecipient( Message.RecipientType.BCC, ia ); message.setSubject(subject); Multipart multipart = new MimeMultipart(); MimeBodyPart messageBodyPart1 = new MimeBodyPart(); messageBodyPart1.setContent(bodyText, "text/plain" ); multipart.addBodyPart(messageBodyPart1); MimeBodyPart messageBodyPart2 = new MimeBodyPart(attachment.getInputStream()); messageBodyPart2.setFileName(attachment.getFileName()); messageBodyPart2.addHeader("Content-Transfer-Encoding","base64"); multipart.addBodyPart(messageBodyPart2); message.setContent(multipart); Transport.send( message );
|
 |
poornima balagopal
Ranch Hand
Joined: Dec 02, 2003
Posts: 83
|
|
Hi, I dont have exact idea. But in my application i was using Java Mail API for sending a mail with attachment. My requirement was to create a file at runtime and then send it as an attachment to multiple users. I have used java mail api only. Its very simple . When we download it , we will get example . I think that will be helpful for you. Try it ok
|
 |
somkiat puisungnoen
Ranch Hand
Joined: Jul 04, 2003
Posts: 1312
|
|
In struts Framework, you can call your send mail program from Subclass of Action Class in Struts Framework. I think, Struts Framework is a workflow control so if you understand concept of struts framework and develop application with it which help you understand in struts framework.
|
SCJA,SCJP,SCWCD,SCBCD,SCEA I
Java Developer, Thailand
|
 |
 |
|
|
subject: sending email attachment with Struts?
|
|
|