KMMailHelper.swift 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. //
  2. // KMMailHelper.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by wanjun on 2023/10/7.
  6. //
  7. import Cocoa
  8. @objcMembers class KMMailHelper: NSObject {
  9. static func sendFile(withPaths paths: [String]) {
  10. var totalFileString: String?
  11. for (index, path) in paths.enumerated() {
  12. let filePath = URL(fileURLWithPath: path).lastPathComponent
  13. if index == 0 {
  14. totalFileString = filePath
  15. } else {
  16. totalFileString?.append(" \(filePath)")
  17. }
  18. }
  19. guard let totalFileString = totalFileString else {
  20. return
  21. }
  22. var attachmentScript = ""
  23. for file in paths {
  24. attachmentScript.append("make new attachment with properties {file name:\"\(file)\"} at before the first paragraph\n")
  25. }
  26. let service = NSSharingService(named: .composeEmail)
  27. service?.subject = totalFileString
  28. var urls: [URL] = []
  29. for file in paths {
  30. urls.append(.init(fileURLWithPath: file))
  31. }
  32. service?.perform(withItems: urls)
  33. }
  34. @objc static func newEmail(withContacts contact: String, andSubjects subjects: String) {
  35. let service = NSSharingService(named: NSSharingService.Name.composeEmail)
  36. service?.recipients = [contact]
  37. service?.subject = subjects//emailString
  38. service?.perform(withItems: [""])
  39. }
  40. }