Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

michaelrdk

macrumors newbie
Original poster
Feb 3, 2014
20
17
Hi,

I want to compose a new Mail message from an AppleScript. This should be fairly easy, but I'm really struggling with getting it to work as intended in macOS Ventura.

I have cut my AppleScript down to the bare minimum example and yet it still fails me with weird formatting issues of the content.

Code:
set theSubject to "Test"
set theContent to "Hello World"

tell application "Mail"
    set default message format to plain format
    activate
    make new outgoing message with properties {subject:theSubject, content:theContent, visible:true}
end tell

My problems with the created message is:
  1. A linebreak is added before "Hello World" in the message content.
  2. The message is created in Rich text format no matter what I do (Mail is set to plain format in settings).
  3. If I manually convert the message to plain text the content gets prefixed with a quote level.
The quote level is also visible for the Rich text content when sent and later viewed on an iOS device.
 

Nygaard

macrumors member
Dec 7, 2022
47
20
Houston
For what it's worth, on macOS Monterey (12.3.1), Mail 16.0 (3696.80.82.1.1), the only issue I see is 2. No rogue quote levels or line breaks, but the default message format is seemingly ignored (always creates rich text).

You could try populating the message from a URL to see if that has a different behavior:

AppleScript:
tell application "Mail" to mailto "mailto:?subject=Test&body=Hello%20World"

Otherwise, if all you want to do is send an automated email (rather than pre-populate a message), you can do it the old fashioned way from the command line with sendmail and friends. However, you need to configure things right for it to work.
 

michaelrdk

macrumors newbie
Original poster
Feb 3, 2014
20
17
[...] on macOS Monterey (12.3.1), Mail 16.0 (3696.80.82.1.1), the only issue I see is 2 [...]
Interesting, I've used this kind of automation for a few years and only recently noticed the added quote level. It makes sense if this is a new bug in Ventura.

You could try populating the message from a URL to see if that has a different behavior [...]
That is clever and it actually works without these formatting issues on Ventura.

However, I do a few other adjustments to the message window itself; such as setting the sender, signature, and attaching a file. It will require some rewriting, and I'm not sure I can get it working without creating other issues, but I hadn't thought of populating the message via a URL.

It seems that my formatting issues is caused by a bug in Ventura, so I've written to Apple about it and hope it will get fixed at some point.

Unfortunately, Sendmail is not an option for various reasons.

Thank you for helping.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.