javamail: why IMAPStore.connect switch to port 993 even if mail.imap.ssl.enable=false and port=143? -
in following code (an ibm domino 9.0.1 java agent) trying connect via port 143 no ssl imap store.
package com.fm; import javax.mail.internet.*; import javax.mail.*; import java.net.connectexception; import java.util.*; public class jsaveimap { private store store=null; private string host; private string port; private string user; private string password; private javax.mail.session mailsession=null; private boolean dodebug; public jsaveimap() { system.out.println("creato oggetto"); } public void savemessage(mimemessage message, string foldername) throws messagingexception { //http://stackoverflow.com/questions/11524716/save-draft-message-using-java-mail-api folder folder=null; if (foldername.length()>0) { folder= store.getfolder(foldername); } else { folder= store.getfolder("inbox"); } if (dodebug) {system.out.println("folder aperto:" + folder.getfullname());} folder.open(folder.read_write); //draftmessage.setflag(flag.draft, true); mimemessage arrmessage[] = {message}; folder.appendmessages(arrmessage); folder.close(false); folder=null; } public boolean connect(string phost, string pport, string puser, string ppassword,boolean dodebug) { boolean retval=false; this.dodebug=dodebug; if (dodebug) {system.out.println(this.getclass().getname()+ ".connect");} if (!(phost.equalsignorecase(host) && pport.equalsignorecase(port) && puser.equalsignorecase(user) && ppassword.equalsignorecase(password))) { // parametri differenti, resetta connessione precedente recycle(); host=phost; port=pport; user=puser; password=ppassword; } system.out.println("host: " + host + ", port: " + port + ", user: " + user + ", password: " + password); try { system.out.println(this.getclass().getname() + " connettiamo?"); //properties props = system.getproperties(); properties props =new properties(); //nuove proprietà per non avere conflitti con quelle gia in uso ad altri account imap props.setproperty("mail.store.protocol", "imap"); if (port.length()>0) { props.setproperty("mail.imap.port", port); } props.setproperty("mail.imap.ssl.enable", "false"); //credo che non serva, oltretutto default =false, poi dovrebbe venire parametrico dall'account props.setproperty("mail.imap.connectiontimeout", "5000"); props.setproperty("mail.imap.timeout", "5000"); mailsession = session.getdefaultinstance(props, null); if (dodebug) { system.out.println("proprietà correnti ************************************************************"); enumeration keys = props.keys(); while (keys.hasmoreelements()) { string key = (string)keys.nextelement(); string value = (string)props.get(key); system.out.println(key + ": " + value); } } if ( dodebug) { mailsession.setdebug(true); } store = mailsession.getstore("imap"); //store=mailsession.getstore(new urlname("imap",host,integer.parseint(port),null,user,password)); //store.connect(host, user, password); store.connect(host, integer.parseint(port), user, password); system.out.println("connesso allo store "+ host + " " +user); retval=true; } catch(nosuchproviderexception ne) { system.out.println("exception in class " + ne.getstacktrace()[0].getclassname() + " method: "+ ne.getstacktrace()[0].getmethodname()+ ", row: " + ne.getstacktrace()[0].getlinenumber() + ": " + ne.tostring()); //questa eccezione non la gestisco perchè è nel caso in cui il provider non supporti // il protocollo. lo escludo per ora ne.printstacktrace(); //throw new messagingexception("errore nella connessione al provider"); } catch (messagingexception ne) { //throw new messagingexception ("messagingexception durante connessione:"+e.getmessage(),e); system.out.println("exception in class " + ne.getstacktrace()[0].getclassname() + " method: "+ ne.getstacktrace()[0].getmethodname()+ ", row: " + ne.getstacktrace()[0].getlinenumber() + ": " + ne.tostring()); ne.printstacktrace(); } catch (exception ne) { system.out.println("exception in class " + ne.getstacktrace()[0].getclassname() + " method: "+ ne.getstacktrace()[0].getmethodname()+ ", row: " + ne.getstacktrace()[0].getlinenumber() + ": " + ne.tostring()); ne.printstacktrace(); } if (dodebug) system.out.println("connect terminata"); return retval; } public void recycle() { try { host=""; port=""; user=""; password=""; //if (folder.isopen()) { folder.close(true);} if (store!=null) { if (store.isconnected()) {store.close();} } } catch (exception ne) { system.out.println("exception in class " + ne.getstacktrace()[0].getclassname() + " method: "+ ne.getstacktrace()[0].getmethodname()+ ", row: " + ne.getstacktrace()[0].getlinenumber() + ": " + ne.tostring()); } } }
why getting exception port 993 in message
couldn't connect host, port: 172.17.0.247, 993;
output:
proprietà correnti ************************************************************ mail.imap.port: 143 mail.imap.ssl.enable: false mail.imap.timeout: 5000 mail.imap.connectiontimeout: 5000 mail.store.protocol: imap debug: setdebug: javamail version 1.5.4 debug: getprovider() returning javax.mail.provider[store,imap,com.sun.mail.imap.imapstore,oracle] debug imap: mail.imap.fetchsize: 16384 debug imap: mail.imap.ignorebodystructuresize: false debug imap: mail.imap.statuscachetimeout: 1000 debug imap: mail.imap.appendbuffersize: -1 debug imap: mail.imap.minidletime: 10 debug imap: closefoldersonstorefailure **debug imap: trying connect host "172.17.0.247", port 143, ** isssl false exception in class com.sun.mail.imap.imapstore method: protocolconnect, row: 731: com.sun.mail.util.mailconnectexception: couldn't connect host, **port: 172.17.0.247, 993; timeout 5000;** nested exception is: java.net.connectexception: connection refused: connect agent manager: agent error: com.sun.mail.util.mailconnectexception: couldn't connect host, port: 172.17.0.247, 993; timeout 5000; nested exception is: java.net.connectexception: connection refused: connect agent manager: agent error: @ com.sun.mail.imap.imapstore.protocolconnect(imapstore.java:731) agent manager: agent error: @ javax.mail.service.connect(service.java:364) agent manager: agent error: @ com.fm.jsaveimap.connect(jsaveimap.java:86)
it getdefaultinstance behaviour due previous imap connection
Comments
Post a Comment