Mail.appからメールを読み取って表示するMacアプリケーションを作成したいのですが、Mail.appからメールを読み取る方法についての情報が見つかりません。私の質問は:
- 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