Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
729 views
in Technique[技术] by (71.8m points)

email - 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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...