java - Javax.mail API giving FolderClosedException -
i have peculiar problem - when run code save email as '.eml' file in independent java program, not face issues. same code when executed part of web application gives folderclosedexception. difference being independent program, have jdk on java 6 javax.mail jar file explicitly provided in classpath, , webapp, jdk java 7 , jar file not provided i.e. uses default jdk implementation. or guidance appreciated.
my code below:
public static void readmailandstorebasic() { properties props = new properties(); list<file> attachments = new arraylist<file>(); props.setproperty("mail.store.protocol", "imaps"); try { session session = session.getinstance(props, null); store store = session.getstore(); store.connect("outlook.office365.com", "xxxxxxxxxxxxxxxxxxx", "xxxxxxxxxxxxxxx"); folder inbox = store.getfolder("up"); inbox.open(folder.read_write); folder processed = store.getfolder("p"); processed.open(folder.read_write); message[] msglist = inbox.getmessages(); inbox.copymessages(msglist, processed); msglist = processed.getmessages(); (message tempmsg : inbox.getmessages()){ tempmsg.setflag(flags.flag.deleted, true); } (message msg : msglist) { address[] in = msg.getfrom(); (address address : in) { system.out.println("from:" + address.tostring()); } object content = msg.getcontent(); if (content instanceof string) { string body = (string) content; // ... } else if (content instanceof multipart && hasattachments(msg)) { saveasemail(msg); } system.out.println("sent date:" + msg.getsentdate()); system.out.println("subject:" + msg.getsubject()); // system.out.println("content:" + bp.getcontent()); } (message tempmsg : processed.getmessages()){ tempmsg.setflag(flags.flag.seen, true); } } catch (filenotfoundexception fe) { } catch (ioexception e) { } catch (exception mex) { mex.printstacktrace(); } } private static void saveasemail(message msg){ try { msg.writeto(new fileoutputstream(new file(mail_location +file.separator+system.currenttimemillis()+".eml"))); } catch (ioexception e) { // todo auto-generated catch block e.printstacktrace(); } catch ( messagingexception me){ // todo auto-generated catch block me.printstacktrace(); } }
Comments
Post a Comment