首页 > 代码库 > Java 连接读取Exchange Server邮件服务器
Java 连接读取Exchange Server邮件服务器
import java.security.GeneralSecurityException;import java.util.Properties;import javax.mail.Folder;import javax.mail.Message;import javax.mail.MessagingException;import javax.mail.Session;import javax.mail.Store;import com.sun.mail.util.MailSSLSocketFactory;public class App { public static void main( String[] args ) throws MessagingException, GeneralSecurityException { MailSSLSocketFactory sf = new MailSSLSocketFactory(); sf.setTrustAllHosts(true); Properties properties = new Properties(); //the host you can give the IP address or the url of Exchange server properties.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","cloud_qa@wesoft.com", "ldap4$qa"); //create the folder object and open it Folder emailFolder = store.getFolder("INBOX"); emailFolder.open(Folder.READ_ONLY); //get the mail count. or you can do others in here Message[] msg = emailFolder.getMessages(); System.out.println(msg.length); System.out.println("----finished------"); }}
Java 连接读取Exchange Server邮件服务器
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。