使用 Swift 打开收件箱中包含特定邮件的邮件应用程序
Open mail app with a specific mail in the inbox with Swift
我的收件箱中有一封电子邮件的 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)
}
}
找到了一个非常简单的解决方案:
要使用给定的 Message-ID 打开邮件应用程序,您只需通过以下消息打开它:URL Scheme.
不需要 AppleScript ;-)。
Button(action: {
NSWorkspace.shared.open(URL(string: "message:%3C...YOUR-MESSAGE_ID....%3E")!)
}) {
Text("Open E-Mail in Mail App")
}
我的收件箱中有一封电子邮件的 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)
}
}
找到了一个非常简单的解决方案:
要使用给定的 Message-ID 打开邮件应用程序,您只需通过以下消息打开它:URL Scheme.
不需要 AppleScript ;-)。
Button(action: {
NSWorkspace.shared.open(URL(string: "message:%3C...YOUR-MESSAGE_ID....%3E")!)
}) {
Text("Open E-Mail in Mail App")
}