Importjava.security.GeneralSecurityException;Importjava.util.Properties;ImportJavax.mail.Folder;ImportJavax.mail.Message;Importjavax.mail.MessagingException;Importjavax.mail.Session;ImportJavax.mail.Store;Importcom.sun.mail.util.MailSSLSocketFactory; Public classApp { Public Static voidMain (string[] args)throwsmessagingexception, generalsecurityexception {mailsslsocketfactory SF=Newmailsslsocketfactory (); Sf.settrustallhosts (true); Properties Properties=NewProperties (); //The host you can give the IP address or the URL of Exchange serverProperties.put ("Mail.imap.host", "10.100.1.x"); Properties.put ("Mail.imap.starttls.enable", "true"); Properties.put ("Mail.imap.ssl.socketFactory", SF); Properties.setproperty ("Mail.imap.starttls.enable", "true"); Properties.setproperty ("SSL. Socketfactory.provider "," My.package.name.ExchangeSSLSocketFactory "); Properties.setproperty ("Mail.imap.socketFactory.class", "My.package.name.ExchangeSSLSocketFactory"); Session emailsession= Session.getdefaultinstance (Properties,NULL); Emailsession.setdebug (true); Store Store= Emailsession.getstore ("IMAP"); Store.connect ("10.100.1.x", "[email protected]", "Ldap4$qa"); //Create the Folder object and open itFolder Emailfolder = Store.getfolder ("INBOX"); Emailfolder.open (folder.read_only); //get the mail count. Or you can do others.message[] msg =emailfolder.getmessages (); System.out.println (msg.length); System.out.println ("----Finished------"); }}
Java connection reads an Exchange Server mail server