My secondary outlook account does not appear in the list given by iterating
over outlook.application CDispatch Session.Accounts
.
So, I'm using 'SentOnBehalfOfName'
instead, as suggested by https://stackoverflow.com/a/57324426/6057650 to sent emails.
And it works, but not at all or completely as I expected, since sent emails are stored in the primary account outbox and not in the secondary account outbox.
import win32com.client as win32
outlook = win32.Dispatch('outlook.application')
# see available mail accounts (no condition, just as info)
for accounts in outlook.Session.Accounts:
print('Available email accounts: %s'%(accounts))
# Create the email to be sent
mail = outlook.CreateItem(0)
mail.SendUsingAccount='secondary_account@email.com'
mail._oleobj_.Invoke(*(64209, 0, 8, 0, 'secondary_account@email.com'))
mail.SentOnBehalfOfName = 'secondary_account@email.com'
mail.To = 'some_address@email.com'
mail.Subject = 'Report'
mail.Body ='Some stuff'
# getting default folder of used Account
myNamespace = outlook.GetNamespace("MAPI")
myFolder = myNamespace.GetDefaultFolder(6)
myFolder.Display()
# see your prepared email
mail.Display()
# Finally
mail.Send()
What I want (and need) is that sent emails be stored in the secondary account outbox (which is shared with other peers and which can be access by them) and not in the main or primary account outbox (which only I can access).