要在Apache POI中读取Outlook邮件中添加的UserProperties,可以使用以下步骤:
org.apache.poi
poi
4.1.2
org.apache.poi
poi-ooxml
4.1.2
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.hpsf.DocumentSummaryInformation;
import org.apache.poi.hpsf.SummaryInformation;
import org.apache.poi.hsmf.MAPIMessage;
import java.io.FileInputStream;
import java.io.IOException;
public class ReadOutlookProperties {
public static void main(String[] args) {
try {
FileInputStream fis = new FileInputStream("path_to_outlook_email.msg"); // 替换为实际的Outlook邮件文件路径
MAPIMessage msg = new MAPIMessage(new POIFSFileSystem(fis));
// 读取Outlook邮件的属性
DocumentSummaryInformation dsi = msg.getSummaryInformation().getDocumentSummaryInformation();
SummaryInformation si = msg.getSummaryInformation();
// 读取UserProperties
String userProperty = msg.getUserProperty("UserPropertyName");
System.out.println("Author: " + si.getAuthor());
System.out.println("Title: " + si.getTitle());
System.out.println("Subject: " + si.getSubject());
System.out.println("User Property: " + userProperty);
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
"path_to_outlook_email.msg"
为实际的Outlook邮件文件路径。"UserPropertyName"
。这样就可以使用Apache POI读取Outlook邮件中添加的UserProperties了。注意,此示例代码仅适用于.msg格式的Outlook邮件文件。如果使用其他格式的Outlook邮件文件(例如.msgx或.pst),则需要根据文件类型使用不同的POI类库进行处理。