You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Daxin Zuo <dz...@techexcel.com> on 2005/01/24 19:48:33 UTC

Sending email with zip file attach problem

Hi,
   Please help. Any sugestion is welcome. In my web page, users send email
with attachment, so upload is related. I can provide the file in either a
byte[] array, or in an inputstream. I try to send the attachement with
JavaMail(I know there is email api in Tomcat-Common. But I have no a good
example).

--- my code in a function in a servlet  ---
DiskFileUpload upload = new DiskFileUpload();
List items = upload.parseRequest(request);
Iterator itr = items.iterator();
item = (FileItem) itr.next();
.....
//----- now it is a attachement. ----
InputStream istrm= item.getInputStream();
... ....
MimeBodyPart messageBodyPart = new MimeBodyPart();
messageBodyPart.setDisposition(Part.INLINE);
messageBodyPart.setContent(strBodyText, "text/plain");
MimeMultipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart);
messageBodyPart = new MimeBodyPart(istrm);
messageBodyPart.setDisposition(messageBodyPart.ATTACHMENT);
messageBodyPart.addHeader("Content-Type",strMime); //strMime is correct
messageBodyPart.setFileName(fileName);
multipart.addBodyPart(messageBodyPart);
....


NO metter what file it is, the attachement received is ATT00211.txt.
I the file is a text file, the contents are correct.
if the file is a small zip file, it adds the lines as following in attached
file:
Content-Type: application/zip; name=idmeta.zip
Content-Disposition: attachment; filename=idmeta.zip
Content-Transfer-Encoding: 7bit

What's wrong? Please forward instruction.



---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


RE: Sending email with zip file attach problem

Posted by Daxin Zuo <dz...@techexcel.com>.
Thanks for the reply. So I have to output the file.
If, in jave, there is no way to upload the file and attach the file
directly, it seems strange.


-----Original Message-----
From: Caroline Jen [mailto:jiapei_jen@yahoo.com]
Sent: Monday, January 24, 2005 11:10 AM
To: Tomcat Users List
Subject: Re: Sending email with zip file attach problem


It is an example of sending bulk mails with
attachment.
You have to write the uploaded file into a temporary
directory.

See the attachments.  I hope the example could be
useful.

-Caroline

--- Daxin Zuo <dz...@techexcel.com> wrote:

>
> Hi,
>    Please help. Any sugestion is welcome. In my web
> page, users send email
> with attachment, so upload is related. I can provide
> the file in either a
> byte[] array, or in an inputstream. I try to send
> the attachement with
> JavaMail(I know there is email api in Tomcat-Common.
> But I have no a good
> example).
>
> --- my code in a function in a servlet  ---
> DiskFileUpload upload = new DiskFileUpload();
> List items = upload.parseRequest(request);
> Iterator itr = items.iterator();
> item = (FileItem) itr.next();
> .....
> //----- now it is a attachement. ----
> InputStream istrm= item.getInputStream();
> ... ....
> MimeBodyPart messageBodyPart = new MimeBodyPart();
> messageBodyPart.setDisposition(Part.INLINE);
> messageBodyPart.setContent(strBodyText,
> "text/plain");
> MimeMultipart multipart = new MimeMultipart();
> multipart.addBodyPart(messageBodyPart);
> messageBodyPart = new MimeBodyPart(istrm);
>
messageBodyPart.setDisposition(messageBodyPart.ATTACHMENT);
> messageBodyPart.addHeader("Content-Type",strMime);
> //strMime is correct
> messageBodyPart.setFileName(fileName);
> multipart.addBodyPart(messageBodyPart);
> ....
>
>
> NO metter what file it is, the attachement received
> is ATT00211.txt.
> I the file is a text file, the contents are correct.
> if the file is a small zip file, it adds the lines
> as following in attached
> file:
> Content-Type: application/zip; name=idmeta.zip
> Content-Disposition: attachment; filename=idmeta.zip
> Content-Transfer-Encoding: 7bit
>
> What's wrong? Please forward instruction.
>
>
>
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> tomcat-user-help@jakarta.apache.org
>
>




__________________________________
Do you Yahoo!?
Yahoo! Mail - Helps protect you from nasty viruses.
http://promotions.yahoo.com/new_mail


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: Sending email with zip file attach problem

Posted by Caroline Jen <ji...@yahoo.com>.
It is an example of sending bulk mails with
attachment.
You have to write the uploaded file into a temporary
directory.

See the attachments.  I hope the example could be
useful.

-Caroline

--- Daxin Zuo <dz...@techexcel.com> wrote:

> 
> Hi,
>    Please help. Any sugestion is welcome. In my web
> page, users send email
> with attachment, so upload is related. I can provide
> the file in either a
> byte[] array, or in an inputstream. I try to send
> the attachement with
> JavaMail(I know there is email api in Tomcat-Common.
> But I have no a good
> example).
> 
> --- my code in a function in a servlet  ---
> DiskFileUpload upload = new DiskFileUpload();
> List items = upload.parseRequest(request);
> Iterator itr = items.iterator();
> item = (FileItem) itr.next();
> .....
> //----- now it is a attachement. ----
> InputStream istrm= item.getInputStream();
> ... ....
> MimeBodyPart messageBodyPart = new MimeBodyPart();
> messageBodyPart.setDisposition(Part.INLINE);
> messageBodyPart.setContent(strBodyText,
> "text/plain");
> MimeMultipart multipart = new MimeMultipart();
> multipart.addBodyPart(messageBodyPart);
> messageBodyPart = new MimeBodyPart(istrm);
>
messageBodyPart.setDisposition(messageBodyPart.ATTACHMENT);
> messageBodyPart.addHeader("Content-Type",strMime);
> //strMime is correct
> messageBodyPart.setFileName(fileName);
> multipart.addBodyPart(messageBodyPart);
> ....
> 
> 
> NO metter what file it is, the attachement received
> is ATT00211.txt.
> I the file is a text file, the contents are correct.
> if the file is a small zip file, it adds the lines
> as following in attached
> file:
> Content-Type: application/zip; name=idmeta.zip
> Content-Disposition: attachment; filename=idmeta.zip
> Content-Transfer-Encoding: 7bit
> 
> What's wrong? Please forward instruction.
> 
> 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> tomcat-user-help@jakarta.apache.org
> 
> 



		
__________________________________ 
Do you Yahoo!? 
Yahoo! Mail - Helps protect you from nasty viruses. 
http://promotions.yahoo.com/new_mail