2

Following some other Stack Overflow code examples of NSWorkspace.shared.open(), I came up with this:

  @IBAction func mailFileVacuum(_ sender: NSButton) {
    let receiver = sender.alternateTitle
    let sendAddress = String(format: "mailto:%@@filevacuum.com?subject=FileVacuum %@", receiver, receiver).addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)!

    NSLog("receiver %@", receiver)

    let mailUrl = URL(string: sendAddress)

    NSLog("mailUrl %@", mailUrl!.absoluteString)

    if NSWorkspace.shared.open(mailUrl!) {
        print("Default browser was successfully opened to send email. ")

    }
  }

☝️ that gets us this

enter image description here

I tried changing the default browser, that's not the issue.

NSLog(mailUrl) logs this mailto%3AFeedback%40filevacuum.com%3Fsubject=FileVacuum%20Feedback

Look good maybe ...

¿Que Paso?

Mikeumus
  • 3,570
  • 9
  • 40
  • 65
  • @LeoDabus, that was just an example. They're all using `UIApplication.shared().openURL(url)` in that example link. I'm using `NSWorkspace.shared.open(url)` from https://developer.apple.com/documentation/appkit/nsworkspace – Mikeumus Oct 03 '19 at 03:08

1 Answers1

4

You should not be percent encoding the entire URL; but rather, its individual components. See the Apple URL Scheme Reference.

The correctly formatted URL should look like (i.e. NSLog(mailUrl) should output):

mailto:Feedback@filevacuum.com?subject=FileVacuum%20Feedback
Chris Zielinski
  • 1,231
  • 1
  • 9
  • 11