0

我想制作一个从 Mail.app 读取电子邮件并显示它们的 Mac 应用程序,但我找不到有关如何从 Mail.app 读取邮件的任何信息。我的问题是:

  1. 如何从 Mail.app 阅读电子邮件?任何建议将不胜感激。
4

1 回答 1

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);

替代使用osascriptthroughNSTask来运行脚本。

编辑(回复评论)

遍历所有消息并将其正文添加到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
于 2012-09-04T13:47:34.780 回答