gpt4 book ai didi

macos - cocoa:从 Mail.app 读取邮件

转载 作者:行者123 更新时间:2023-12-03 17:35:24 26 4
gpt4 key购买 nike

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

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

最佳答案

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

关于macos - cocoa:从 Mail.app 读取邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12260054/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com