gpt4 book ai didi

swift - OS X swift 发送带附件的邮件

转载 作者:行者123 更新时间:2023-11-28 12:20:19 27 4
gpt4 key购买 nike

我使用 swift for osx。我有这个发送邮件的代码:

let service = NSSharingService(named: NSSharingServiceNameComposeEmail)!
service.recipients = ["abc@domain.de"]
service.subject = "My Subject"
service.perform(withItems: ["My Message"])

但我想附上一个 pdf 文件。我怎样才能实现它?

最佳答案

这项工作 see

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)

关于swift - OS X swift 发送带附件的邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45088856/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com