Reputation: 4258
i working with swift for osx. i have this code for sending mails:
let service = NSSharingService(named: NSSharingServiceNameComposeEmail)!
service.recipients = ["[email protected]"]
service.subject = "My Subject"
service.perform(withItems: ["My Message"])
but i would like attach a pdf file. how can i realize it ?
Upvotes: 1
Views: 1049
Reputation: 147
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)
Upvotes: 3