Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Java > Java and JDK > JSP Basics
Password Reminder
Register
| FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 2nd, 2006, 04:53 AM
Registered User
 
Join Date: Dec 2006
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Working with Attachments

Hi I m Deepak...
m doin a project on JavaMail..
m able to retrieve all the mails from the mail server..
can send mails back to different locations.but i hv a problem...
plz help me out..

m not able to retrieve the attachments from the mailserver..
can read the mails..but nt the attachments from a particular mail..
m using the following code for this..:-


<%@ 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 = "164.100.144.3";
String username = "support.vsp";
String password = "wel.come";
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(i);

  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>


from this code m not able to read out the attachments by including the values of i in the for loop(i= the mail no havin the attachments in the mail server)



plz help me out..
where i m wrong..
after tat i hv to save the attachments in a particular folder.
i hv just removed tat saving part from the code.(in /* */)
first off all i hv to read the attachments.after tat the saving process would b done..
help...

wat should i do..where m wrong..

Reply With Quote
  #2 (permalink)  
Old December 5th, 2006, 04:59 AM
Registered User
 
Join Date: Dec 2006
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hey frnd...help yaar...

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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... deepakkumar0511 JSP Basics 0 December 20th, 2006 06:41 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



All times are GMT -4. The time now is 05:39 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.