我想创建一个Mac应用程序,它从Mail.app读取电子邮件并显示它们,但我找不到有关如何从Mail.app读取邮件的任何信息。我的问题是:
答案 0 :(得分:3)
Applescript可能是最简单的方法,例如:
tell application "Mail"
set theMessage to message 1 of inbox
set theBody to content of theMessage as rich text
end tell
通过NSAppleScript
运行脚本,快速脏示例(无错误处理等):
NSString *theSource = @"tell application \"Mail\"\n"
"set theMessage to message 4 of inbox\n"
"set theBody to content of theMessage as rich text\n"
"end tell\n"
"return theBody";
NSAppleScript* theScript = [[NSAppleScript alloc] initWithSource:theSource];
NSAppleEventDescriptor* theDescriptor = [theScript executeAndReturnError:NULL];
NSLog(@"%@", theDescriptor);
替代使用osascript
到NSTask
来运行脚本。
编辑(回复评论)
遍历所有消息并将其正文添加到theMessages
列表。
set theMessages to {}
tell application "Mail"
set theCount to get the count of messages of inbox
repeat with theIncrementValue from 1 to theCount by 1
set TheMessage to message 1 of inbox
set theBody to content of TheMessage as rich text
set end of theMessages to theBody
end repeat
end tell
return theMessages