Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > JSP Basics
| Search | Today's Posts | Mark Forums Read
JSP Basics Beginning-level questions on JSP. More advanced coders should post to Pro JSP.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the JSP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old December 20th, 2006, 06:41 AM
Registered User
 
Join Date: Dec 2006
Location: Delhi, Delhi, India.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Working with Attachments...

hello friends...
i m new to java....
m trying to make a project on javamail...
i am able to send recieve mails through javamail..
i am also able to send attachments...
but there is a problem in fetching the attachments...
i m tryin fr a long tme..
plz help me out...
here is the code i hv used fr it...


<%@ page import="java.util.Properties"%>
<%@ page import="javax.mail.*" %>
<%@ page import="java.io.*" %>
<%@ page import="javax.servlet.http.HttpServletRequest" %>
<%@ page import="javax.mail.internet.*"%>


<html>
<body>

<%

String host = "ABC";
String username = "XYZ";
String password = "MNO";
String protocol = "imap";


Properties props = System.getProperties();

    // Setup mail server
    props.put("mail.smtp.host", host);

    // Get session
    Session mysession = Session.getInstance(props, null);


Message message = new MimeMessage(mysession);

BodyPart messageBodyPart = new MimeBodyPart();

// Create a Multipart
    Multipart multipart = new MimeMultipart();

Multipart mp = (Multipart)message.getContent();


//for (int i=0, n=multipart.getCount(); i<n; i++)

  Part part = multipart.getBodyPart(1820);

  String disposition = part.getDisposition();

  if ((disposition != null) && ((disposition.equals(Part.ATTACHMENT)) || disposition.equals(Part.INLINE)))
  {
System.out.println("Stram values::"+part.getInputStream()+"::Disposition::"+ part.getDisposition());
 /*
if(filepath != null)
                               {
                                  String filename=filepath+"/"+ part.getFileName();
                                 System.out.println("filename path::"+filename);
                                  File file = new File(filename);
                                  InputStream in=part.getInputStream();
                                  FileOutputStream fos = new FileOutputStream(file);
                                      byte[] buf = new byte[1024];
                                      int c=0;
                                      while((c=in.read(buf)) != -1)
                                      {
                                          fos.write(buf, 0, c);
                                      }
                                   in.close();
                                   fos.close();
                               }
   //saveFile(part.getFileName(), part.getInputStream());

}
}

// from saveFile()
 File file = new File(filename);
for (int i=0; file.exists(); i++)
{
// file = new File(filename+i);
}

if (disposition == null) {
  // Check if plain
  MimeBodyPart mbp = (MimeBodyPart)part;
  if (mbp.isMimeType("text/plain")) {
    // Handle plain
  } else {
    // Special non-attachment cases here of
    // image/gif, text/html,...
*/
  }
}
%>

</body>
</html>


first i want to show the attachments...
after tat wil save these attachmenst to a particular folder i want...


any help would b gr8...

thnx...




Similar Threads
Thread Thread Starter Forum Replies Last Post
Working with Attachments azmarkb BOOK: Access 2007 VBA Programmer's Reference ISBN: 978-0-470-04703-3 0 July 14th, 2007 07:36 PM
Working with Attachments deepak0511 JSP Basics 1 December 5th, 2006 04:59 AM
Regarding Attachments mvnaidu ASP.NET 1.0 and 1.1 Professional 2 June 26th, 2006 07:49 AM
attachments nishant_k JSP Basics 2 December 10th, 2004 04:19 PM
attachments lily611 Forum and Wrox.com Feedback 1 June 15th, 2004 08:37 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.