在Java程式設計設計中,我們如何通過Java讀取郵件呢?下面小編為大家介紹了Java讀取郵件的'方法,希望能幫到大家!
複製程式碼 程式碼如下:public void receive() throws Exception {
Log.e(tag, "receive()");
// sharedpreference讀取資料,用split()方法,分開字串。
SharedPreferences pre = getSharedPreferences("SAVE_INFORMATION",MODE_WORLD_READABLE);
String content = "name;pass";//tring("save", "");
String[] Information = t(";");
String username = Information[0];
String password = Information[1];
Properties props = new Properties();
Session session = efaultInstance(props);
// 取得pop3協議的郵件服務器
Store store = tore("pop3");
// 連線郵件伺服器
ect("", username, password);
// 返回資料夾物件
Folder folder = older("INBOX");
// 設定僅讀
(_ONLY);
// 獲取資訊
Message message[] = essages();
for(int j=0; j<th; j++) {
Log.e(tag, "message[i]ubject()="+message[j]ubject());
Log.e(tag, "message[i]ontent()="+message[j]ontent());
}
e(true);
e();
}