AppleScript to send HTML email via Mail.app?

Trying to send an email through Mail.app (mostly so I don’t have to mess with storing my credentials in a PHP script!), and found an AppleScript that I’ve tweaked slightly for my needs. This is on a 2012 Mini running Catalina:

tell application "Mail"
	
	set theFrom to "<my email address>"
	set theTos to {"<my email address>"}
	set theCcs to {}
	set theBccs to {}
	
	set theSubject to "Email Subject"
	
	set theContent to "<HTML>
<BODY bgcolor=\"#99CCFF\">
<H1>Hi There</H1>
<p>Test HTML Content.</p> 
</BODY>
</HTML>"
	set theSignature to ""
	set theAttachments to {}
	set theDelay to 1
	
	set theMessage to make new outgoing message with properties {sender:theFrom, subject:theSubject, visible:false}
	tell theMessage
		set html content to theContent
		set content to theContent
		
		repeat with theTo in theTos
			make new recipient at end of to recipients with properties {address:theTo}
		end repeat
		repeat with theCc in theCcs
			make new cc recipient at end of cc recipients with properties {address:theCc}
		end repeat
		repeat with theBcc in theBccs
			make new bcc recipient at end of bcc recipients with properties {address:theBcc}
		end repeat
		repeat with theAttachment in theAttachments
			make new attachment with properties {file name:theAttachment as alias} at after last paragraph
			delay theDelay
		end repeat
	end tell
	
	send theMessage
	
end tell

You’ll notice there are two “set content” lines. One with HTML, one without. I only left them both in so you can see the syntax/formatting I’m using - I only use one at a time.

I read that “set html content” is what I need to do, and when I compile in Script Editor the words turn purple like the other message attributes - so I have to think I’m at least setting some valid attribute.

But when I do “set html content”, the message sends, but it’s blank.

When I do “set content”, the message sends, and I see raw HTML in my message.

Obviously neither is optimal. :slight_smile:

Can anybody spot anything that’s obviously wrong with the code?

Maybe it’s an ongoing issue?

https://macscripter.net/viewtopic.php?id=44503

If true, that sucks.

Not that I absolutely need the HTML email, but it would sure help. :slight_smile: