This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Struts and the fly likes sending email attachment with Struts? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "sending email attachment with Struts?" Watch "sending email attachment with Struts?" New topic
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
 
jQuery in Action, 2nd edition
 
subject: sending email attachment with Struts?
 
Similar Threads
Email Java object in memory
JavaMail:Why can't a recipient using Lotus Notes see the attachment of my mail
Struts FormFile to java.io.File
Java Mail: Cant set email body text when including email attachment
java mail attachment notification