2012-09-04 24 views
0

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

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

回答

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

其它用途osascriptNSTask运行脚本。

编辑通过所有消息(回应评论)

环路和自己的身体增加了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 
+0

参见脚本桥,你在ObjC做到这一点,这将让:http://robnapier.net/blog/scripting-bridge-265 –

+0

有没有办法让所有的邮件?像'设置邮件消息所有的收件箱'? – NOrder

+0

您可以遍历所有消息获取其内容。新增了一个快速示例 – Anne