How can I set the recipient of any outbound message (new, reply, forward) using the Outlook Contacts?
I’m running Outlook 2011 Ver 14.5.2 (latest update I think) on Mavericks (10.9.5).
For example, the “forward” action includes a "[to text] parameter, but only accepts an email address, not the contact’s name.
If I am creating an email manually, I can enter the contact’s name (like “John Doe”) and it will auto-complete and auto-fill the recipient field. How do I do this using AppleScript?
From my old VBA days I seem to remember setting the Recipient field with a name, and then running a “Resolve” method, which would use that name to find the contact, and return the complete name and address to the Recipient object. Anything like this in AppleScript?
I have done extensive searching in this forum and elsewhere, and have not found anything of help.
tell application "Microsoft Outlook"
activate
# Just a little demo code
# set addressBook to first address book
# tell addressBook
# email addresses of (contacts whose first name is "Christopher" and last name is "Stone")
# end tell
set newMessage to make new outgoing message with properties {subject:"Hooray for Automation!", content:"Just a test."}
tell newMessage
make new recipient with properties {email address:{name:"Christopher Stone"}} # My name is already in Outlooks Contacts.
open
end tell
# Any given name and address:
# make new recipient at newMessage with properties {email address:{name:"Christopher Stone", address:"junksieve@thestoneforge.com"}}
end tell
Yep, that’s the one. I did not get that you could just enter the Contact’s name without an address, and it would search Contacts. It looked to me that you had to enter both the name and email address.
Things seem to work quite differently with FORWARDED messages. If you create a forwarded msg AND open it immediately in a window, then changes to Recipients are NOT shown in the window.
The KEY is to NOT open the new msg in a window at first.
Here’s my test script, which seems to work OK:
Running Microsoft Outlook 2011 (14.7.2) on macOS 10.11.6.
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"