You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Joe Latty <jo...@team2media.com> on 2002/05/01 07:12:54 UTC
RE: Struts and JavaMail
As it turns out for anyone who is interested, I was using the 1.1-b1 and
begrudgingly I have rolled all code back to 1.0.2 and it works the way it
is.
Seems the bug is in 1.1-b1 eh?
Joe
-----Original Message-----
From: Joe Latty [mailto:joe@team2media.com]
Sent: Tuesday, 30 April 2002 10:07 AM
To: Struts Users Mailing List
Subject: Struts and JavaMail
I am attempting to send a file (that has been uploaded with the file tag) as
an attachment using JavaMail. I am using some very standard code that I have
used before many times, the only difference is now I am using Struts and it
is not working.
Is anyone else successfully sending files as email attachments?
Is there some sort of conflict with the Multipart Object (I know I'm
clutching at straws, but this is incredibly frustrating).
Code excerpt:
...
try {
MimeMessage message = new MimeMessage(session);
// From
message.setFrom( new InternetAddress(from));
InternetAddress[] tos = InternetAddress.parse(to);
// To
message.setRecipients(Message.RecipientType.TO,tos);
// Subject
message.setSubject(subject);
// Date
message.setSentDate(new Date());
if (fileName == null) message.setText(bodyText);
else {
// The body
MimeBodyPart body = new MimeBodyPart();
body.setContent(bodyText, "text/html");
// The attachment
MimeBodyPart attachment = new MimeBodyPart();
FileDataSource source = new FileDataSource(fileName);
attachment.setDataHandler(new DataHandler(source));
attachment.setFileName(source.getName());
// The Multipart to which body and attachment are added
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(body);
multipart.addBodyPart(attachment);
// DEBUG print out of the multipart
// This will print out the message body and file contents...
multipart.writeTo(System.out);
// The MimeMessage has the multipart added
message.setContent(multipart);
}
Transport.send(message);
...
TIA
Joe
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>