Create mail with attachment using applescript and outlook - outlook

I've wrote a litte Applescript to make a new message with an attached file via outlook. But it didn't work and I don't know why. There is no error or something else. The message is created in the Draft-section of outlook, but the attachment is missing. Can somebody help me out?
Here's the Script:
set mailBody to "<span>TEST</span>"
set mailAdress to text returned of (display dialog "Mail Adress" default answer "" buttons {"OK"} default button 1) as string
set whichFile to file
tell application "Finder" to set whichFile to selection
repeat with aFile in whichFile
tell application "Microsoft Outlook"
set filename to name of aFile
set theNewMessage to make new outgoing message with properties {subject:"TEST " & filename, content:mailBody}
make new recipient at theNewMessage with properties {email address:{address:mailAdress}}
set theAttachmentFile to aFile as POSIX file
make new attachment at the end of theNewMessage with properties {file:theAttachmentFile}
open theNewMessage
end tell
end repeat
Greetings and thanks in advance
Speedster

Here is what I have been using as an alternative. To use the below, you need the desired message to be queued up already in your outbox. Or you can just borrow a few lines of the below and work it into your existing code.
set theAttachmentFile to "Macintosh HD:Users:Speedster:Documents:Attachment.docx" as alias
---replace this with the hard address of your selected file
tell application "Microsoft Outlook"
repeat with theMessage in the messages of the outbox
make new attachment at the end of theMessage with properties {file:theAttachmentFile}
end repeat
end tell

Related

Apple Mail and Applescript

I have has this script working fine on Outlook 2011 for Mac all on a local machine.
I have now found out my "rules" will now work on Apple mail after all these years.
The last part of the rule is to run this script which then sends an HTML email back to the sender.
If I change the tell application "Microsoft Outlook" to tell the application "Mail", I keep getting Syntax Errors and it highlights the "mail folder" telling me it is wrong.
I am stumped.
I am using Exchange with the Mail app. Not sure if that may be the issue?
tell application "Microsoft Outlook"
set replyToMessage to message 1 of mail folder "•HOT FOLDER•"
if (replyToMessage is "") then
log ("NOTHING SELECTED!")
return
end if
set replyMessageSubj to subject of replyToMessage
set replyMessage to reply to replyToMessage without opening window
set contentHTML to "Vault:Users:vault:Documents:VAULT:Digital_Subscription_Reply:Digital_issue22.html" as alias
set contentHTML to read contentHTML
set the content of replyMessage to contentHTML
set the subject of replyMessage to "Vault Digital Issue - Issue 22"
send replyMessage
end tell
Every scriptable application has its own scripting dictionary with its own unique terminology. We can't just change tell application "Microsoft Outlook" to tell application "Mail" and expect it to work, because Mail and Outlook use different keywords for their equivalent objects. I don't have outlook installed on my machine, so I can't compile or run the original script, but I've modified it as best I can to use Mail terminology. No guarantee this will work, but it will compile and run so you can (at least) test it.
tell application "Mail"
set replyToMessage to message 1 of mailbox "•HOT FOLDER•"
if (replyToMessage is "") then
log ("NOTHING SELECTED!")
return
end if
set replyMessageSubj to subject of replyToMessage
set replyMessage to reply replyToMessage without opening window
set contentHTML to "Vault:Users:vault:Documents:VAULT:Digital_Subscription_Reply:Digital_issue22.html" as alias
set contentHTML to read contentHTML
set the content of replyMessage to contentHTML
set the subject of replyMessage to "Vault Digital Issue - Issue 22"
send replyMessage
end tell
When you're in Script Editor, select "Open Dictionary..." from the File menu and scroll down to open the Mail scripting dictionary. That will give you all the relevant terminology for scripting Mail.app.

Applescript for Outlook v15 - Recipients won't populate

I have copied some scripts on the site and the result is that Outlook creates a new forwarded message but the recipient is blank. Have tried multiple forms but always the blank recipient. It's a script I will only run for messages I manually select, so I can't use a simple forwarding rule in the app.
Any ideas?
tell application "Microsoft Outlook"
repeat with eachSelectedMessage in selectedMessages
set theForwardedMessage to forward eachSelectedMessage with opening window
make new recipient at theForwardedMessage with properties {email address:{address:"recipient#somewhere.com", name:"Lumpkin Skinbark"}}
send theForwardedMessage
end repeat
end tell
New information: It turns out the recipient is being populated correctly and put in my Outbox, but not being sent. In addition, a new window pops up with the same forwarded message and a blank recipient. That new window was the one I saw that led me to believe the recipient was not populating.
My workaround for now is to periodically hit the send/receive button in Outlook to send the messages sitting in the Outbox (I don't know why they don't just get sent automatically like everything else). Then I added:
close window 1
to close the open window -- don't know why it's created and don't want it, but might as well just close it and move on.
So I do have it working, but it's not elegant.
I finally figured out how to make this work: DON'T Open the forwarded email window until AFTER you've set the email properties, especially the Recipients.
Here's my test script:
set newSubjectStr to "TEST -- DON'T OPEN at first."
set recipientEmail to "somebody#InvalidDomainName.com"
tell application "Microsoft Outlook"
set selMsg to current messages
set oMsg to item 1 of selMsg
set subjectStr to subject of oMsg
set oFwdMsg to ¬
forward oMsg without opening window ## This is KEY. Don't Open Window
make new recipient at oFwdMsg ¬
with properties {email address:{address:recipientEmail}}
set subject of oFwdMsg to newSubjectStr
--- NOW OPEN FWD EMAIL WINDOW ---
open oFwdMsg
end tell
--- SEND NOW IF NO MORE CHANGES ---
-- Works fine if I manually send, or use keyboard shortcut --
-- Send and Close Window ---
delay 0.2
tell application "Microsoft Outlook" to activate
tell application "System Events"
key code 36 using {command down} -- CMD-RETURN
end tell
--- BELOW SEND BY SCRIPT LEAVES MSG IN OUTBOX ---
--send oFwdMsg
--close window 1
--sync folder "Outbox"
NOTE to Moderators: Is there a way to get syntax highlight for AppleScript?

how to get the subject of my outlook email to mac clipboard through an applescript?

I am new to applescript. I am trying to get the subject of the selected outlook (2011) email with the following applescript.
tell application "Microsoft Outlook"
set theMessage to the current messages
get the subject of theMessage
end tell
But I am getting the following error message.
Can’t get subject of {incoming message id 392990 of application "Microsoft Outlook"}
Can someone please help me?
I am completely new to AppleScript ... and am wanting a script to extract a list of both the the 'subject line' and 'date received' from a specific batch of emails in Outlook 2011.
Is this possible.
The script above works great for extracting the subject line from one highlighted email.
Many thanks
Simon
The reason this does not work is that set theMessage to the current messages returns a list. Notice the { }
tell application "Microsoft Outlook"
set theMessage to first item of (get current messages)
set theSubject to the subject of theMessage
end tell
set the clipboard to theSubject

Set text of a Growl Notification using Automator?

I have an Automator Application containing the action "Show Growl Notification", which is always empty when it appears. I've tried using the "Get Specified Text" and "Get Value Of Variable" actions directly before it, but nothing I've tried seems to work.
The code sample from gadgetmo is almost correct but won't work as is with Growl 1.4
An application must be registered and enabled and must provide a list of notifications it will present and also a list of which of those notifications are enabled.
You can skip all that config stuff if you just hijack the preconfigured automator settings as shown below.
Key points to note are "Automator notification" as the name of the notification and "Automator" as the source application.
tell application "System Events"
set isRunning to (count of (every process whose bundle identifier is "com.Growl.GrowlHelperApp")) > 0
end tell
if isRunning then
tell application id "com.Growl.GrowlHelperApp"
notify with name ¬
"Automator notification" title ¬
"Processing Files" description ¬
input as text application name "Automator"
end tell
end if
Use this in a Run Applescript:
tell application "System Events"
set isRunning to (count of (every process whose bundle identifier is "com.Growl.GrowlHelperApp")) > 0
end tell
if isRunning then
tell application id "com.Growl.GrowlHelperApp"
notify with name ¬
"Test Notification" title ¬
"Test Notification" description ¬
"This is a test AppleScript notification." application name "Growl AppleScript Sample"
end tell
end if
Or download it here.
You can also use this with input.
The action just passes the input through, and doesn't have any text fields that accept variables, so you will need to manually put in the message you want. The Show Growl Notification action (located inside the GrowlHelperApp bundle) does use an AppleScript, so you could modify a copy to do something like use the input if the message field is blank.

How can I open a new email using AppleScript, setting "To:", "Subject:", and attaching a file?

To help my users report problems easily, I want to create as much of an email as possible. Most importantly, I want to attach a file (the log file).
How can I do this in AppleScript?
tell application "Mail"
set theMessage to make new outgoing message with properties {visible:true, subject:"My Subject", content:"My Body"}
tell theMessage
make new to recipient at end of to recipients with properties {name:"Ben Waldie", address:"applescriptguru#mac.com"}
end tell
tell content of theMessage
make new attachment with properties {file name:pathToFile} at after last paragraph
end tell
end tell

Resources