OSX swift发送带有附件的邮件
我和斯威夫特一起为osx工作。 我有发送邮件的代码:OSX swift发送带有附件的邮件,swift,macos,email,cocoa,Swift,Macos,Email,Cocoa,我和斯威夫特一起为osx工作。 我有发送邮件的代码: let service = NSSharingService(named: NSSharingServiceNameComposeEmail)! service.recipients = ["abc@domain.de"] service.subject = "My Subject" service.perform(withItems: ["My Message"]) 但我想附上一份pdf文件。 我怎样才能实现它呢?这项工作 let em
let service = NSSharingService(named: NSSharingServiceNameComposeEmail)!
service.recipients = ["abc@domain.de"]
service.subject = "My Subject"
service.perform(withItems: ["My Message"])
但我想附上一份pdf文件。
我怎样才能实现它呢?这项工作
let email = "your email here"
let path = "/Users/myname/Desktop/report.txt"
let fileURL = URL(fileURLWithPath: path)
let sharingService = NSSharingService(named: NSSharingServiceNameComposeEmail)
sharingService?.recipients = [email] //could be more than one
sharingService?.subject = "subject"
let items: [Any] = ["see attachment", fileURL] //the interesting part, here you add body text as well as URL for the document you'd like to share
sharingService?.perform(withItems: items)