简体   繁体   English

OS X快速发送带附件的邮件

[英]OS X swift send mail with attachment

i working with swift for osx. 我为osx使用swift。 i have this code for sending mails: 我有此代码用于发送邮件:

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

but i would like attach a pdf file. 但我想附上pdf文件。 how can i realize it ? 我该怎么实现呢?

this work 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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM