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:
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:
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 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:
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