When I try to use myRtfString (an object with class ConcreteAttributedString) as the body of an email message, it is not accepted:
tell application “Mail”
set theMessage to make new outgoing message with properties {visible:true, content:myRtfString}
– the attempt above to use the NSConcreteAttributedString fails with an error:
(Mail got an error: Can’t get «class ocid» id «data optr00000000206CA30000600000».)
-- but a plain text string works as expected:
set theMessage to make new outgoing message with properties {visible:true, content:"a plain text string"}
A google search reveals that lots of people have run into this roadblock over the years. I have tried getting the rich text from the pasteboard without success. Has anyone found a solution?
In X-Code, I can load a file and extract myRtfString as an NSAttributedString and then I can use “sharing” to create a rich text email message:
NSSharingService* myMailShareService = [NSSharingService sharingServiceNamed:NSSharingServiceNameComposeEmail];
NSArray* shareItems = @[myRtfString];
[myMailShareService performWithItems:shareItems];
This produces a “message” with the expected rich text content displayed in a new window in Mac Mail. The sharing service also supports setting the to: addresses, the subject, and it supports adding enclosures. BUT the documentation does not mention setting the cc: or bcc: fields, not does it mention how to set a specific sender account. It seems like there should be some way to expose these other message attributes to the NSSharingService interface in X-Code - any ideas how to do this?
After creating a rich text message with myMailShareService, I can get a reference to the new message using AppleScript by searching for its title in the Drafts mailbox. But the found object has class “message”, unlike the the object produced by Applescript above, which has class “outgoing message”. All the attributes of “message”, are read only - unlike an “outgoing message” where they are read/write. So how would I convert a “message” to an “outgoing message” so it can be edited (e.g. fill in the cc: field)?
Thanks in advance for any ideas or solutions.