Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a message with attachment in Outlook using applescript

I'm trying to open a new message window in Microsoft Outloook version 15.6 and populate the fields including an attachment. Here's my actionscript code:

tell application "Microsoft Outlook"
    set newMessage to make new outgoing message with properties {subject:"Hooray for automation"}
    make new recipient at newMessage with properties {email address:{name:"Jim Shank", address:"[email protected]"}}
make new attachment at the end of newMessage with properties {file:"/tmp/Invoice INV2 - Paul.pdf"}
    open newMessage
end tell

(This message was derived from this stack overflow question).

However, I get this error: 256:398: execution error: Microsoft Outlook got an error: Error while saving the changed record property. (-2700)

Is it possible to use actionscript to open a new message in the latest version of Outlook?

like image 328
Mark Avatar asked Jun 01 '15 13:06

Mark


2 Answers

Here is an applescript one; maybe it'll help?

tell application "Microsoft Outlook.app"
activate
set theFile to "Macintosh HD:Users:Shared:sp.zip"
set newMessage to make new «class outm» with properties {«class subj»:"Outlook is back"}
make new «class rcpt» at newMessage with properties {«class emad»:{name:"Mark", «class radd»:"[email protected]"}}
tell newMessage
    set theAttachment to make new «class cAtc» with properties {file:theFile}
    «event mailsend»
end tell
end tell
like image 110
user3069232 Avatar answered Nov 02 '22 21:11

user3069232


I found the solution: I needed to add the following line at the front of the script:

set x to "/Users/foo/file" as POSIX file

See this page for details: How do I attach a file to a new message in Microsoft Outlook via AppleScript?

like image 34
Mark Avatar answered Nov 02 '22 20:11

Mark