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

スクリプトを実行するための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
于 2012-09-04T13:47:34.780 に答える