hi,
    I had used this is JSP, hope this would be help full to you..
Smita

If it is sending the attachment it is some thing like this,
**********************************************************

        //Text part
         BodyPart bodyPart1=new MimeBodyPart();
         bodyPart1.setText(\"Sedning mail from JSP, please ignore this \");
         //file part
         BodyPart bodyPart2=new MimeBodyPart();
         FileDataSource fileDataSource=new 
FileDataSource(\"/usr/local/weblogic/myserver/public_html/index.html\");
         bodyPart2.setDataHandler(new DataHandler(fileDataSource));
         bodyPart2.setFileName(fileDataSource.getName());

         Multipart multipart = new MimeMultipart();
         multipart.addBodyPart(bodyPart1);
         multipart.addBodyPart(bodyPart2);

***********************************************************
And if it is receving the attachments it is some thing as follows,
***********************************************************


                if(message[i].isMimeType(\"multipart/*\"))
                        {
                                Multipart multipart=(Multipart)message[i].getContent();
                                for(int j=0;j<multipart.getCount();j++)
                                {
                                        Part p=multipart.getBodyPart(j);
                                        if(p.isMimeType(\"text/html\"))
                                        {
                                                extContent=p.getContent().toString();
                                                %>
                                                <table width=\"75%\" cellpadding=0 
cellspacing=0 topmargin=0 leftmargin=0 align=center>
                                                <tr>
                                                <td align=left 
width=600><%=extContent%></td>
                                                </tr>
                                                <table>
                                                <br><br>
                                                <%
                                        }
                                        else if(p.isMimeType(\"text/plain\"))
                                        {
                                                extContent=p.getContent().toString();

                                                %>
                                                <table width=\"75%\" cellpadding=0 
cellspacing=0 topmargin=0 leftmargin=0 align=center>
                                                <tr>
                                                <%

                                                extContent=extContent+\">>\";
                                                String newMessage=\"\";
                                                StringTokenizer stTok=new 
StringTokenizer(extContent,\">>\");
                                                while(stTok.hasMoreTokens())
                                                {
                                                        String part=stTok.nextToken();
                                                        
newMessage=newMessage+\"<br>\"+part;
                                                        //  out.println(\"\\n\"+part);
                                                        extContent=newMessage;
                                                }

                                                %>
                                                <td align=left width=600  
><%=newMessage%></td>
                                                </tr>
                                                </table>

                                                <br><br>
                                                <%
                                        }
                                        else if(p.isMimeType(\"message/rfc822\"))
                                        {
                                                extContent=p.getContent().toString();
                                                %>
                                                <table width=\"75%\" cellpadding=0 
cellspacing=0 topmargin=0 leftmargin=0 align=center>
                                                <tr>
                                                <td align=left width=600 
><%=extContent%></td>
                                                </tr>
                                                <table>
                                                <br><br>
                                                <%
                                        }

                                        else if(p.isMimeType(\"multipart/*\"))
                                        {
                                                Multipart mp=(Multipart)p.getContent();
                                                Part pNew=mp.getBodyPart(0);
                                                
extContent=pNew.getContent().toString();
                                                %>
                                                <table width=\"75%\" cellpadding=0 
cellspacing=0 topmargin=0 leftmargin=0 align=center>
                                                <tr>
                                                <td align=left width=600 
><%=extContent%></td>
                                                </tr>
                                                <table>
                                                <br><br>
                                                <%
                                        }

                                        else
                                        {
                                                String fileName=p.getFileName();

                                                java.io.File file=new 
java.io.File(\"/usr/local/weblogic/myserver/public_html/JavaMail/\", fileName);
                                                
FileList=FileList+fileName+\"&\"+file.length()+\":\";
                                                FileOutputStream fos=new 
FileOutputStream(file);
                                                BufferedOutputStream  bos=new 
BufferedOutputStream(fos);

                                                InputStream bis=p.getInputStream();

                                                int aByte;
                                                while((aByte=bis.read())!=-1)
                                                {
                                                        bos.write(aByte);
                                                }
                                                bos.flush();
                                                bos.close();
                                                bis.close();



************************************************************



\"Rodelio A. Pagui\" <[EMAIL PROTECTED]>:

> Hi, all!
>
> I hope somebody can help me out on how to handle attachments with
> JavaMail.
>
> Thanks.
>
> Rodel
>
> ===========================================================================
> To unsubscribe: mailto [EMAIL PROTECTED] with body: \"signoff
> JSP-INTEREST\".
> For digest: mailto [EMAIL PROTECTED] with body: \"set JSP-INTEREST
> DIGEST\".
> Some relevant FAQs on JSP/Servlets can be found at:
>
>  http://archives.java.sun.com/jsp-interest.html
>  http://java.sun.com/products/jsp/faq.html
>  http://www.esperanto.org.nz/jsp/jspfaq.jsp
>  http://www.jguru.com/faq/index.jsp
>  http://www.jspinsider.com
>

-------------------------------------------------
This mail helped a tree grow. Know more at http://green.sify.com

Take the shortest route to success!
Click here to know how http://education.sify.com

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://archives.java.sun.com/jsp-interest.html
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.jsp
 http://www.jguru.com/faq/index.jsp
 http://www.jspinsider.com

Reply via email to