我看到你正在使用Java。你可以嘗試使用jacob框架。 使用Jacob框架的先決條件是加載jacob dll庫。
爲了讀取郵件和其他郵件屬性你可以通過鏈接 https://msdn.microsoft.com/en-us/library/office/aa210946(v=office.11).aspx
假設下進行 - 您正在嘗試通過讀取Outlook客戶端郵件。
要存儲來自郵件的附件,您可以嘗試使用下面的代碼。
ActiveXComponent xl = new ActiveXComponent(
"Outlook.Application");
Dispatch explorer = Dispatch
.get(xl, "ActiveExplorer").toDispatch();
Dispatch selection = Dispatch.get(explorer,
"Selection").toDispatch();
Variant count = Dispatch.get(selection, "Count");
int toInt = count.getInt();
for(int j=1;i<=toInt;i++){
Dispatch mailItem = Dispatch.call(selection,
"Item", new Variant(j)).toDispatch();
Dispatch attachs = Dispatch.get(mailItem, "Attachments").toDispatch();
Variant count1 = Dispatch.get(attachs, "Count");
int numberOfAttach = count1.getInt();
for (int i = 1; i <= numberOfAttach; i++) {
Attachment attach = new Attachment();
Dispatch attachment = Dispatch.call(attachs, "Item",
new Variant(i)).toDispatch();
//get the name of the file
Variant nameOfFile = Dispatch.get(attachment, "DisplayName");
String displayName = nameOfFile.getString();
Variant type = Dispatch.get(attachment, "Type");
Variant saveAttachment = null;
saveAttachment = Dispatch.call(attachment, "SaveAsFile","path where attachment need to be saved");
}
}
來源
2015-02-25 11:07:18
Raj