Mail: Create HTML-formatted Auto-response With AppleScript and Rules

Hello everyone

I was hoping for a bit of help creating an Applescript that enables me to send HTML auto response emails in OS X Mail using a Rule. I’m new to Applescript so please excuse my complete lack of knowledge on the subject. I messed around with a few scripts found here on the forum but none of them seemed to work properly.

The following script worked fine but I don’t know how to replace the email “content” with HTML content

using terms from application "Mail"
   on perform mail action with messages theMessages for rule theRule
       tell application "Mail"
           repeat with thisMessage in theMessages
               set AppleScript's text item delimiters to {""}
               set thisSender to sender of theMessages
               
               set theNewMessage to reply thisMessage with opening window
               tell theNewMessage
                   set fromAccount to account "mynewaccount"
                   set content to "This is an automated reply. Your message has been forwarded to my new e-mail address. For future reference, please update your records by replacing my former address oldusername@olddomain.com with my new address newusername@newdomain.com .

Thankyou,
Lance"
               end tell
               
               send theNewMessage
               
           end repeat
       end tell
   end perform mail action with messages
end using terms from

I’ve tried this script that I found here - http://jacobsalmela.com/os-x-mail-create-html-formatted-auto-response-applescript-rules/ but I doesn’t seem to work well. It just sends a blank auto response email.

using terms from application "Mail"
	on perform mail action with messages theMessages for rule theRule
		tell application "Mail"
			repeat with eachMessage in theMessages
				set theName to extract name from sender of eachMessage
				if exists reply to of eachMessage then
					set theAddress to reply to of eachMessage
				else
					set theAddress to extract address from sender of eachMessage
				end if
				set customHTML to "<html><body><h1>Thanks</h1><p>for emailing me.</p></body></html>"
				set newMessage to make new outgoing message with properties {html content:customHTML}
				tell newMessage
					make new to recipient at end of to recipients with properties {name:theName, address:theAddress}
					set visible to false
					set subject to "Re: " & subject of eachMessage
				end tell
				send newMessage
				tell eachMessage
					set was replied to to true
				end tell
			end repeat
		end tell
	end perform mail action with messages
end using terms from

I should add that the auto response email I want to send is from an email alias and not from my default email. I found this script on the forum, but again I don’t know how to make it work.

set theAccount to "put-your-account-email-here@mail.com"
set the_mailto to "email@mail.com"
tell application "Mail"
   activate
   set newMessage to make new outgoing message with properties {sender:theAccount, address:the_mailto}
   tell newMessage
       set visible to true
       make new to recipient at end of to recipients with properties {address:the_mailto}
   end tell
end tell

So is there any way I can magically combine these scripts into one single script that actually works for me? Any help would be highly appreciated. :wink:
P.S. I’m got OS X El Capitan 10.11 on my iMac

The described problem was reported too on applescript-users@lists.apple.com.
As far as I know there is no workaround available at this time.
I’m too busy on tasks requiring a “robust” system to boot under 10.11.2 to test if it’s already solved.

Yvan KOENIG running El Capitan 10.11.1 in French (VALLAURIS, France) mardi 8 décembre 2015 10:39:48

Is it true that html content in Mac Mail has been broken since Yosemite?

The following code used to work for me, I’ve left out the definitions of some of the variables but I’m sure you get the idea. I was using Mavericks last time it worked but now I’ve tried it in Yosemite and El Capitan and it doesn’t work any more.


set theContent to "<html><body><h1>Hi there</h1><body></html>"

tell application "Mail"
	
	##Create the message
	set theMessage to make new outgoing message with properties {sender:MySender, subject:theSubject, visible:false}
	
	##Set a recipient
	tell theMessage
		set html content to theContent
		make new to recipient with properties {name:recipientName, address:recipientAddress}
		##Send the Message
		send
	end tell
end tell

I get an empty email if I do this. Now it seems I cannot add “html content” any more, only “content”. If this is true, how do we apply formatting to emails composed with AppleScript?