• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

sending email attachment with Struts?

 
Mitch Abaza
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic