Saturday, October 1, 2022

#1 2016-03-15 01:11:35 pm

WalterB
Member
Registered: 2015-12-30
Posts: 4

How can I tell Outlook which email account I want it to use?

OSX 10.10.4
MS Outlook for Mac 2011

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.

Can anyone help?

TIA

Offline

 

#2 2016-03-16 08:16:46 am

TecNik
Member
From:: Applescript-Leeds-England-UK
Registered: 2003-04-02
Posts: 569

Re: How can I tell Outlook which email account I want it to use?

Hi Walter,

Welcome to MacScripter!

Does this help:

Applescript:


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

Last edited by TecNik (2016-03-16 08:17:28 am)

Offline

 

#3 2016-03-16 08:24:15 am

WalterB
Member
Registered: 2015-12-30
Posts: 4

Re: How can I tell Outlook which email account I want it to use?

YES!:o

You magnificent fellow you, that works perfectly!

Thanks so much!

Offline

 

#4 2016-03-16 08:27:33 am

TecNik
Member
From:: Applescript-Leeds-England-UK
Registered: 2003-04-02
Posts: 569

Re: How can I tell Outlook which email account I want it to use?

Thanks Walter.
Glad to hear it helped. smile

Offline

 

#5 2021-01-02 09:45:52 pm

csmac1980
Member
Registered: 2020-12-31
Posts: 3

Re: How can I tell Outlook which email account I want it to use?

I can not get my Gmail accounts to work using this for Outlook 365/2019 16.44 - Do you know what needs to be fixed or updated?

Last edited by csmac1980 (2021-01-02 09:46:16 pm)

Offline

 

#6 2021-06-16 10:28:31 am

Mockman
Member
From:: Toronto
Registered: 2020-05-27
Posts: 239

Re: How can I tell Outlook which email account I want it to use?

Well, that is what a default account is smile

Your gmail account isn't an exchange account so it would be filtred out by the above. Does your gmail account work otherwise?

If so, try and identify it in a script:

Applescript:

tell application "Microsoft Outlook"
   
   name of account 2

end tell

Then use that for your account property.


Filed under: Gmail, Outlook

Offline

 

#7 2022-09-20 06:32:26 am

peetysmith
Member
Registered: 2022-01-13
Posts: 8

Re: How can I tell Outlook which email account I want it to use?

I'm trying to do the same also and pulling my hair out.

Mockman I tried your "name of account" approach for 1 and 2 and in both instances got "Microsoft Outlook got an error: Can’t get account 1"

Any ideas?

My outlook is set up with 2 Google accounts and I need to be able to switch between them.

Thanks in advance.
Pete

Offline

 

#8 2022-09-20 08:09:35 am

KniazidisR
Member
From:: Greece
Registered: 2019-03-03
Posts: 2531

Re: How can I tell Outlook which email account I want it to use?

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.

Last edited by KniazidisR (2022-09-20 08:26:22 am)


Model: MacBook Pro
OS X: Catalina 10.15.7
Web Browser: Safari 14.1
Ram: 4 GB

Offline

 

#9 2022-09-21 01:22:37 am

peetysmith
Member
Registered: 2022-01-13
Posts: 8

Re: How can I tell Outlook which email account I want it to use?

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:

Applescript:

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

Offline

 

#10 2022-09-21 08:57:18 am

KniazidisR
Member
From:: Greece
Registered: 2019-03-03
Posts: 2531

Re: How can I tell Outlook which email account I want it to use?

peetysmith wrote:

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.


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?


Model: MacBook Pro
OS X: Catalina 10.15.7
Web Browser: Safari 14.1
Ram: 4 GB

Offline

 

#11 2022-09-21 11:32:13 am

estockly
Member
Registered: 2009-01-03
Posts: 132

Re: How can I tell Outlook which email account I want it to use?

Which version of Outlook are you using?

Offline

 

#12 Yesterday 03:08:51 am

peetysmith
Member
Registered: 2022-01-13
Posts: 8

Re: How can I tell Outlook which email account I want it to use?

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.

Offline

 

#13 Yesterday 09:53:35 am

kerflooey
Member
Registered: 2011-07-07
Posts: 226

Re: How can I tell Outlook which email account I want it to use?

Hi:

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.

k

Offline

 

#14 Yesterday 10:56:37 pm

peetysmith
Member
Registered: 2022-01-13
Posts: 8

Re: How can I tell Outlook which email account I want it to use?

Thanks kerlflooey.

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.

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)