Sometimes I really like Outlook. What was really messed up app half a dozen years ago is (before New Outlook) a really good app. The AppleScript support is very nice, for instance.
Today I'm going to create an email in Outlook with Html in AppleScript.
Let's have some data for email with a subject, a text message, some html, a name and an email. Notice that all the quotes have to be escaped. I always do my scripts with Mail Archiver where I can set the properties directly without quoting. This is much easier.
Then a new email needs to be made with "new outgoing message". The subject can be set directly.
There is an option in Outlook if it prefers text or html emails when creating emails with the name "has html". If text is preferred then the "plain text content" of the new email is set. For html the "content" is set.
The recipient of an email in Outlook is a bit complicated because it needs a name and an address.
The final trick is to open the new message.
This gives me the following script:
property theSubject : "theSubject"
property BodyText : "test"
property BodyHtml : "<h1 style=\"font-family:-apple-system;\">This is a headline level 1</h1><h2 style=\"font-family:-apple-system;\">This is a headline level 2</h2><blockquote><p style=\"font-family:Helvetica;font-size:16px;color:red;text-align:left;\"> Nulla vitae elit libero, a pharetra augue. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec sed odio dui.</p></blockquote>"
property theName : "the name"
property theEmail : "[email protected]"
tell application "/Applications/Microsoft Outlook.app"
set theMsg to make new outgoing message
set subject of theMsg to theSubject
if has html of theMsg then
set content of theMsg to BodyHtml
else
set plain text content of theMsg to BodyText
end if
make new to recipient at theMsg with properties {email address:{name:theName, address:theEmail}}
open theMsg
activate
end tell
Here is the result of the script:
The html has a H1 and a H2 headline. Then it has some red indented text. The indentation is due to a blockquote. Keep this in mind for the next article about (almost) creating an email with AppleScript in Mail.