On iOS Unread has a Mail Content article action. This lets customers quickly compose an email with the HTML content of an article. It uses MFMailComposeViewController. MFMailComposeViewController has the unfortunate limitation of only working with Apple Mail, but it is otherwise great. The Mail Content article action is popular with my customers.

macOS has a Compose Email Sharing Service, making it easy for an app to ask the system to create an email message with a recipient, subject, and message body. I was excited to find that this service works with the user’s default email client. It is not limited to Apple Mail.

The Compose Email Sharing Service can accept either a plain text string, or an attributed string with formatting and embedded images.

But after spending more time working with the Compose Email Sharing Service, I was disappointed by some of its weaknesses.

Bugs Around Embedded Images

When sharing articles as rich text, I found that embedded images often get moved to the end of the article. I was able to generate a simple test case – an attributed string with an embedded image at the beginning of it. If I share that attributed string with the sharing service, Apple Mail will generate a message with the image moved to the end. I filed FB13668576 documenting this.

Plain Text Messages

If Apple Mail’s Message format setting (under the Composing pane of the Apple Mail settings window) is set to Plain Text, outgoing messages created using the sharing service are converted to plain text. All formatting and embedded images are lost. Arguably that is the correct behavior because it honors the user’s message format setting.

However a bigger problem is that there is no spacing between paragraphs. The resulting message for a multi-paragraph article is a wall of text. If Unread had a way to determine whether Apple Mail’s message format setting was plain text, Unread could add its own blank lines between paragraphs. But since I cannot find a way to get that information from a sandboxed Mac app, I can either share an attributed string with formatting and embedded images or I can share a plain text string with my own Markdown-like formatting. I cannot do both.

Third Party Email Apps

When the user’s default email client is something other than Apple Mail and an app sends an attributed string, the email client just gets the plain text. The plain text version of the string will also lack basic plain text formatting such as blank lines between paragraphs.

Scripting Apple Mail Directly

I considered trying to send an Apple Event to Apple Mail, hoping that I could simply tell Apple Mail to create an outbound email message with specific HTML content. However the sdef for Apple Mail states that setting the html content attribute of an outgoing message has no effect. The setting is deprecated. My testing confirms that setting that attribute has no effect.

Feedback Reports

I filed these feedback reports

  • FB13668659: .composeEmail NSSharingService - Multiple paragraphs, Plain Text Message Format
  • FB13669961: Formatting lost when sharing multi-paragraph attributed strings to third party email clients via the .composeEmail NSSharingService
  • FB13668576: When creating an email using the .composeEmail NSSharingService using an attributedString, images are moved to the bottom of the message

I find using NSWorkspace.shared.open(URL) with a mailto: URL instead of the Compose Email Sharing Service to be about twice as fast for sending plain text email.