Hi Braun,

After upload file you have to save that in local or any where then attach.
I think you are not saving file.
Try this.

Thanks,
Jeeva.P

-----Original Message-----
From: Braun, James F [mailto:[EMAIL PROTECTED] 
Sent: Friday, April 28, 2006 9:18 AM
To: Struts Users Mailing List
Subject: [Friday] struts and email

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.



-- 
Greetings!

 


ICICI Infotech is now 3i Infotech.


The e-mail addresses of the company's employees have been changed to <existing 
name>@3i-infotech.com. You are requested to take note of this new e-mail ID and 
make use of the same in future

 
"This e-mail message may contain confidential, proprietary or legally 
privileged information. It should not be used by anyone who is not the original 
intended recipient. If you have erroneously received this message, please 
delete it immediately and notify the sender. The recipient acknowledges that 3i 
Infotech or its subsidiaries and associated companies, (collectively "3i 
Infotech"), are unable to exercise control or ensure or guarantee the integrity 
of/over the contents of the information contained in e-mail transmissions and 
further acknowledges that any views expressed in this message are those of the 
individual sender and no binding nature of the message shall be implied or 
assumed unless the sender does so expressly with due authority of 3i Infotech. 
Before opening any attachments please check them for viruses and defects."

Reply via email to