The goal is to upload a file and have it automatically emailed to a
recipient. 
 
In my .jsp page I have:
   <html:file property="attachment" styleClass="textBody"/>
 
In my action form I have:
  private FormFile attachment;
 
My email code looks like this:
  void sendMessage()
  {
    try // multipart/mixed
    {
      // Get system properties
      Properties props = System.getProperties();
 
      // Setup mail server
      props.put("mail.smtp.host", DCL.emailHost);
 
      // Get session
      Session session = Session.getDefaultInstance(props, null);
 
      // Define message
      MimeMessage message = new MimeMessage(session);
 
      // from
      message.setFrom(new InternetAddress(from));
      // to
      message.addRecipient(Message.RecipientType.TO, new
InternetAddress(to));
      // subject
      message.setSubject(subject);
 
      // create multipart container
      Multipart multipart = new MimeMultipart();
 
      // message text
      BodyPart messageBP = new MimeBodyPart();
      messageBP.setText(text);
      multipart.addBodyPart(messageBP);
 
      // attachment
      if(attachment != null)
      {
        try
        {
          ByteArrayInputStream in = new
ByteArrayInputStream(attachment.getFileData(),0,attachment.getFileSize()
);
          MimeBodyPart mimein = new MimeBodyPart(in);
          mimein.setFileName(attachment.getFileName());
 
          //DataSource source = new MimePartDataSource(mimein);
 
          //MimeBodyPart attachBP = new MimeBodyPart();
          //attachBP.setDataHandler(new DataHandler(source));
 
          //attachBP.setFileName(attachment.getFileName());
          multipart.addBodyPart(mimein);
        }
        catch(MessagingException ex1)
        {
        }
        catch(FileNotFoundException ex1)
        {
        }
        catch(IOException ex1)
        {
        }
      }
 
      // assemble parts
      message.setContent(multipart);
 
      // Send message
      Transport.send(message);
    }
    catch(MessagingException ex)
    {
    }
  }
 
The problem is that the file is corrupted when it gets delivered. It
starts out as a 17k file and gets delivered as a 13k file.
 
Can anyone help point out where I'm going wrong and/or a better way to
do this? It's driving me nuts. (nothing to pack a lunch for I admit)
 
Thanks, J.



J. Braun
Polaroid Corp.
Waltham MA USA
+1 781.386.6871
+1 781.424.1159 mobile
[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]> 
 
Excellence through execution.
 
 

-- 
This transmission is intended only for use by the addressee(s) named herein and 
may contain information that is proprietary, confidential and/or legally 
privileged. If you are not the intended recipient, you are hereby notified that 
any disclosure, copying, distribution, or use of the information contained 
herein (including any reliance thereon) is STRICTLY PROHIBITED. If you received 
this transmission in error, please immediately contact the sender and destroy 
the material in its entirety, whether in electronic or hard copy format. Thank 
you.


Reply via email to