1. Export the certificate for the exchange server from Internet explorer Certificate export wizard e.g. after opening https://webmail.hostname.com, (View certificate >Details > Copy to File). Say the exported file name is certificate.cer
2. Create keystore from the certificate using java keytool (which will create keystore file in current directory). It will ask for a password, give anything (it does not matter)
keytool -import -alias webmail.hostname.com -keystore keystore -file certificate.cer
3. Now While running the Java application pass the VM parameter : -Djavax.net.ssl.trustStore=Path_To_keystoreFile
Sample code to read mail is provided below (Its uses JEC API: http://www.javaexchangeconnector.com/)
import java.text.*;
import java.util.*;
import jec.*;
import jec.dto.*;
public class FetchSecureExchangeMail {
public static void main(String args[]) throws Exception {
ExchangeConnectorFactory factory = new ExchangeConnectorFactory();
ExchangeConnectorInterface connector = factory.createExchangeConnector(“webmail.hostname.com”, “username”,”password”, “Exchange”, true, “username@hostname.com”);
SimpleDateFormat dateFormat = new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss”);
Date sinceDate = dateFormat.parse(“2007-04-25 06:00:00″);
HashSet fromEmailAddressFilter = null;
HashSet toEmailAddressFilter = null;
int maxEmailsReturned = 100;
ArrayList emailsArrayList = connector.getEmails(
sinceDate,
fromEmailAddressFilter,
toEmailAddressFilter,
maxEmailsReturned);
System.out.println(“emailsArrayList.size() : ” + emailsArrayList.size());
if (emailsArrayList.size() > 0) {
ExchangeEmailDTO email1 = (ExchangeEmailDTO) emailsArrayList.get(0);
System.out.println(“email1 email1.getSubject(): ” +
email1.getSubject());
}
}
}
Note from Author :
I maintain my website, write articles and reply comments because of my interest/hobby to share information and knowledge.
If you liked the post, Please
Follow me on twitter: http://twitter.com/pankajbatracom
Join My facebook page: http://www.facebook.com/pankajbatra.blog
Join me on LinkedIn: http://www.linkedin.com/in/batrapankaj
Or subscribe to updates by Email by clicking here
Related posts:


Hello,
what is ExchangeEmailDTO?
Thanks!