Saturday, January 19, 2019

#1 2011-08-12 11:55:33 am

SharkusMarkus
Member
Registered: 2003-02-24
Posts: 7

Applescript, Mail.app, HTML and Attached files

Hello all,
In the past I've happily been sending emails by scripting Mail.app and attaching a zip file to said message.

The problem now comes as someone want's an html formatted email, and maintain the attached zip file as well.

The code I was using previously was:

Applescript:

tell application "Mail"
   set theNewMessage to make new outgoing message with properties {subject:themailmessagesubject, content:themailmessagebodycontent, visible:true}
   tell theNewMessage
       make new to recipient at end of to recipients with properties {address:themailmessagerecipientlist}
       
       tell content
           make new attachment with properties {file name:themailmessageattachement as alias} at after the last word of the last paragraph
       end tell
   end tell
   
end tell

To get HTML to work, I changed the content item from content to html content:

Applescript:

tell application "Mail"
   set theNewMessage to make new outgoing message with properties {subject:themailmessagesubject, html content:themailmessagebodycontent, visible:true}
   tell theNewMessage
       make new to recipient at end of to recipients with properties {address:themailmessagerecipientlist}
       
       tell content
           make new attachment with properties {file name:themailmessageattachement as alias} at after the last word of the last paragraph
       end tell
   end tell
   
end tell

The message does get created and sent, but when received the attachment is not present sad No error was given my applescript

it dawned on me that perhaps "tell content" needed to be "tell html" content, so I made that change:

Applescript:

tell application "Mail"
   set theNewMessage to make new outgoing message with properties {subject:themailmessagesubject, content:themailmessagebodycontent, visible:true}
   tell theNewMessage
       make new to recipient at end of to recipients with properties {address:themailmessagerecipientlist}
       
       tell html content
           make new attachment with properties {file name:themailmessageattachement as alias} at after the last word of the last paragraph
       end tell
   end tell
   
end tell

This time I do get an error:
"Mail got an error: Can’t make last paragraph of html content of outgoing message id 9 into type reference"

Anyone have any ideas as to what I am doing wrong? Is there a better way to get mail to send HTML and an attachment, or do I need to use something other than mail.app and if so, what should I use?

Thanks smile

Offline

 

#2 2013-07-23 02:42:01 pm

Mark Munro
Member
Registered: 2008-01-16
Posts: 175
Website

Re: Applescript, Mail.app, HTML and Attached files

Wow, that's an old post. Did you ever find an answer? I am trying to figure this out right now with no luck so far.

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)