开发者

Searching Outlook Global Address List

I'm pulling up the Global Address List from Outlook like so...

 Microsoft.Office.Interop.Outlook.Application oApp = new Microsoft.Office.Interop.Outlook.Application();
 AddressList gal = oApp.Session.GetGlobalAddressList();

...with the aim of eventually being able to search through this in my own application to retrieve contact information which I can then supply to a method that squirrels off an email. Unfortunately given that my own GAL has about 20K entries in (the customers much more) using a foreach or something simply doesn't work in an acceptable timeframe.

I want to pass a string like "Tom" to a method and have it return a list of possible contacts. Is this possible outside of actually opening up Outlook and creating the mail there?

Note: There are a couple of other questions similar to this开发者_如何学JAVA but most seem to have no good answer. I'm hoping I have more luck.


Ok, after a LOT of Googling and stress I still haven't come up with a good way to do this. My work around is to search the local contacts folder of a user using this MSDN example. The local contacts folder of any of my users is generally well under a thousand (actually normally well under a hundred) and so there is no real overhead to searching it.

If the users local directory turns up nothing (or they try and send an email to an invalid address using my apps email functionality) then I get Outlook to provide me with with a non-modal "new email" window which has all the body, attachments, title and so on built for me, and the user can use Outlooks search functionality to find the address from the GAL.

Sort of like this...

if(CantFindAddressesLocally)
{
     MailItem email = (MailItem)(oApp.CreateItem(OlItemType.olMailItem));
     email.Subject = "MY SUBJECT";
     email.Body = "MY BODY";
     email.Attachments.Add(myAttachment);
     email.Display(false) //popup an Outlook "New Email" window
}

Admittedly clumsy since it requires using the Outlook interface (and avoiding that was the whole point of incorporating email functionality in the first place) but at least it generates an email - the only thing left to the user is to input an address that is actually valid.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜