Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send mail from non default account which is not in the sessions accounts

I have created the following...

Outlook.MailItem oMail;
oMail = Inspector.CurrentItem;
Outlook.NameSpace session = oMail.Session;
Outlook.Accounts accounts = session.Accounts;

When looping through accounts, I get the accounts which has been added physically in Outlook, but not the ones added through the “Open these addition mailboxes” in Account Settings -> Change -> More Settings -> Advanced

How can I access those and get the account information from that so I can use it in my, oMail.SendUsingAccount = account

like image 972
Christian M Avatar asked Feb 02 '26 06:02

Christian M


1 Answers

In Outlook 2007+, the code below will provide you with the delegate Exchange mailboxes a given user has access to (the "Open these additional mailboxes" listing). The key ingredient is the Session data Stores and the ExchangeStoreType.

foreach (var store in Globals.ThisAddIn.Application.Session.Stores.Cast<Outlook.Store>().Where(c=>c.ExchangeStoreType == Outlook.OlExchangeStoreType.olExchangeMailbox)) 
            Trace.WriteLine(store.DisplayName);

To send a message on behalf of another mailbox, you should use the property MailItem.SendOnBehalfName - since you technically only have one account (see this Outlook forums post).

like image 190
SliverNinja - MSFT Avatar answered Feb 04 '26 00:02

SliverNinja - MSFT



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!