// // KMMailHelper.swift // PDF Reader Pro // // Created by wanjun on 2023/10/7. // import Cocoa @objcMembers class KMMailHelper: NSObject { static func sendFile(withPaths paths: [String]) { var totalFileString: String? for (index, path) in paths.enumerated() { let filePath = URL(fileURLWithPath: path).lastPathComponent if index == 0 { totalFileString = filePath } else { totalFileString?.append(" \(filePath)") } } guard let totalFileString = totalFileString else { return } var attachmentScript = "" for file in paths { attachmentScript.append("make new attachment with properties {file name:\"\(file)\"} at before the first paragraph\n") } let service = NSSharingService(named: .composeEmail) service?.subject = totalFileString var urls: [URL] = [] for file in paths { urls.append(.init(fileURLWithPath: file)) } service?.perform(withItems: urls) } @objc static func newEmail(withContacts contact: String, andSubjects subjects: String) { let service = NSSharingService(named: NSSharingService.Name.composeEmail) service?.recipients = [contact] service?.subject = subjects//emailString service?.perform(withItems: [""]) } }