我正在处理从桌面Outlook应用程序中提取信息的内容。它适用于我尝试过的大多数文件夹,但对于那些有近十年电子邮件的人来说,我得到了一个"异常获得' ReceivedTime':&#39 ;内存不足,无法继续执行程序。"这就是我正在尝试的:
# New Outlook object
$ol = new-object -comobject "Outlook.Application";
# MAPI namespace
$mapi = $ol.getnamespace("mapi");
# Folder/Inbox
$folder = $mapi.Folders.Item('name@email.com').Folders.Item('Inbox')
# Sort by the Received Time
$contents = $folder.Items | sort ReceivedTime
# Get the first element in the array, convert to JSON, and then output to file
echo $contents[0] | convertTo-Json | Out-File C:\Users\ME\outlook_1.json -Encoding UTF8
有没有更好的方法来接近这个?我是关于Powershell 5.1的。
编辑:我也试过这个,它循环遍历数组,然后在第一个实例上中断,但收到了同样的错误:
# New Outlook object
$ol = new-object -comobject "Outlook.Application";
# MAPI namespace
$mapi = $ol.getnamespace("mapi");
# Folder/Inbox
$folder = $mapi.Folders.Item('name@email.com').Folders.Item('Inbox')
# Sort by the Received Time
$contents = $folder.Items | sort ReceivedTime
$i = 1
foreach($item in $contents){
if (-not ([string]::IsNullOrEmpty($item))){
echo $item | convertTo-Json | Out-File Out-File C:\Users\ME\outlook_1.json -Encoding UTF8-Encoding UTF8
Break
}
}
答案 0 :(得分:2)
使用import java.util.*;
class Guest {
String name;
static Scanner sc = new Scanner(System.in);
Guest() {
name = "NN";
}
void setName() {
//static Scanner sc = new Scanner(System.in);
name = sc.next();
}
void printName() {
System.out.println(name);
}
}
class Room {
Guest guest;
int number;
// Room() {
// number = 1;
//}
void newGuest() {
guest = new Guest();
}
void nameGuest() {
guest.setName();
}
void printRoom() {
System.out.println(number);
guest.printName();
}
}
class Hotel {
Room[] rooms;
Hotel(int b){
rooms = new Room[b];
}
void printRooms() {
for(int i=0; i<rooms.length; i++) {
rooms[i].printRoom();
System.out.println();
}
}
public static void main(String[] args) {
new Hotel(4).demo();
}
void demo() {
for(int i=0; i<rooms.length; i++) {
rooms[i].newGuest();
rooms[i].nameGuest();
}
printRooms();
}
}
对项目集合进行排序,然后使用Items.Sort("ReceivedTime", false)
阅读第一项。
确保将Items(1)
集合存储在变量中,而不是多次访问Items
,否则每次执行此操作时都会获得一个全新的MAPIFolder.Items
对象。
编辑:我是问题的OP,并且正在为那些可能像我一样密集并且最初没有意识到所说内容的人提供正确的代码!
Items