I have two different email accounts set up in Outlook. How can I tell AppleScript to send email from one particular account? So far it always defaults to the primary account, and I can’t find the name of the message property that (I guess?) controls it.
tell application "Microsoft Outlook"
-- The account types are:
-- 'exchange account', 'pop account', 'imap account', and 'ldap account'
set theAccount to the first exchange account whose name is "The-name-of-the-account-you-want-to-use"
set theMessage to make new outgoing message with properties {account:theAccount}
open theMessage
end tell
I don’t use Outlook, but I know that the user’s security policy is tighter on newer operating systems.
You need to 1) open the Internet Accounts pane in the System Preferences application, 2) drag (manually) the accounts you want to activate (for you Mac machine) from the right side of the window to the left side.
The dragging will enable (unlock) them for your Mac OS.
Then click on your dragged iCloud accounts one by one and set the checkbox for Outlook.app. This action will enable Outlook.app to use them correctly.
This manual actions is not scriptable for user’s security.
Hey - thanks for the reply. I’m not sure that this would be the issue given that Outlook already has access to my Gmail and calendar - I use it daily for my email and calendar Mgmt of my Gmail accounts.
However I did look to try this… I don’t see what you mean by “drag (manually)”. In the Internet Accounts screen I have a list on the left of the active accounts and then a list of different providers on the right that I can click to start the setup process accordingly. I was not able to drag one of the provider logos from the right to the left. Is there something I’m missing?
I did click the Google account on the right and follow the process, giving my Mac access to the Calendar (it now shows up in the Mac Calendar app). I tried running the script again and still no joy - it detects no accounts.
I also tried running the following script to see if I was looking for the right type of account and again I got 0 results:
tell application "Microsoft Outlook"
set email_accounts to {}
repeat with emailAccount in imap accounts
set end of email_accounts to (full name of emailAccount) & ":" & (email address of emailAccount)
end repeat
repeat with emailAccount in exchange accounts
if exchange type of emailAccount is equal to primary account then
set end of email_accounts to (full name of emailAccount) & ":" & (email address of emailAccount)
end if
end repeat
repeat with emailAccount in pop accounts
set end of email_accounts to (full name of emailAccount) & ":" & (email address of emailAccount)
end repeat
repeat with emailAccount in ldap accounts
set end of email_accounts to (full name of emailAccount) & ":" & (email address of emailAccount)
end repeat
email_accounts
end tell
Explain this point because I can’t understand. Are you saying that granting access to Mac Mail.app you further check the effect in Outlook.app? Why is nothing said about granting access to Outlook.app?
estockly - using version 16.63 in “old” mode so that I can still use AppleScript.
KniazidisR - I tried to give access to my Mac calendar app to gmail just so that something on my Mac had access granted in that internet accounts window. There was no option to provide outlook with access there. It does that within Outlook itself.
FYI, I ran the script in #9 above and it returned my Exchange account correctly with no errors. That’s the only account I have. I’m running Outlook v16.65 (Applescriptable) on Catalina.
It seems it works fine with everything else other than gmail accounts. My work Mac has an exchange through outlook, will try adding my gmail to that and seeing what comes back. It’s really odd.