我看到你正在使用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