Java connection reads an Exchange Server mail server

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.