【发布时间】:2023-03-20 18:50:01
【问题描述】:
我在收件箱中有一封电子邮件的 UID。 现在我想打开 Apple Mail(或 Outlook)以将该邮件呈现给用户。 我发现的所有示例都是如何启动标准邮件程序来撰写新的电子邮件。
任何想法,锄头来解决这个问题。 我尝试使用 Applescript,但它不起作用。
import SwiftUI
struct ContentView: View {
var body: some View {
Button(action: {
present_Email()
}) {
Text("Show E-Mail")
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
}
}
func present_Email()
{
let myAppleScript = """
tell application "Mail"
set myMessages to messages 1 through 1 of inbox
repeat with aMesseage in myMessages
open (contents of aMesseage)
end repeat
end tell
"""
var error: NSDictionary?
if let scriptObject = NSAppleScript(source: myAppleScript) {
scriptObject.executeAndReturnError( &error)
}
}
【问题讨论】:
-
你有eml文件的路径吗?
-
@davidev 很遗憾,没有,只是之前 IMAP 搜索中的 uid。
-
我建议您在脚本编辑器中单独开发和调试 AppleScript 代码。一旦你让它在那里工作,你就可以将它集成到你的 Swift 代码中。 (对于不平凡的任务,您会发现 [通过 AppleScript-ObjC 桥调用 AS] 比使用 NSAppleScript 更容易。)无论哪种方式,您都需要捕获并处理任何可能出现的 AS 错误。
标签: swift macos email io applescript