[英]Read mail from office 365 in java
我必須使用以下代碼讀取來自Office 365的郵件,但未連接到服務器:
private void init()
{
try{
Properties smtpProps = new Properties();
smtpProps.put("mail.host", "192.168.10.18");
smtpProps.put("mail.port", "995");
smtpProps.put("mail.transport.protocol", "imaps");
session = Session.getInstance(smtpProps,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("abc@abc.om","test");
}
});
System.out.println("session = "+session);
Store store = session.getStore("imaps");
store.connect();
Folder inbox = store.getFolder("INBOX");
inbox.open(Folder.READ_WRITE);
Message messages[] = null;
messages = inbox.search(new FlagTerm(new Flags(Flag.SEEN), false));
System.out.println("leng = "+messages.length);
}catch(Exception e)
{
e.printStackTrace();
}
}
在命令提示符下執行此命令。 如果收到“連接到192.168.10.18 ...無法打開與主機的連接,端口995:連接失敗”的響應,則說明與防火牆的連接問題。
C:\>telnet 192.168.10.18 995
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.