簡體   English   中英

OS X快速發送帶附件的郵件

[英]OS X swift send mail with attachment

我為osx使用swift。 我有此代碼用於發送郵件:

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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM