简体   繁体   English

如何以编程方式访问Exchange 2003专用(联系人)项目

[英]How To Access Exchange 2003 Private (Contact) Items Programmatically

I'm looking for a way to programmatically (.Net) access PRIVATE contact folders on an Exchange 2003 server, to create a subfolder where to create contacts from a database. 我正在寻找一种以编程方式(.Net)访问Exchange 2003服务器上的PRIVATE联系人文件夹的方法,以创建用于从数据库创建联系人的子文件夹。

The solutions I found so far rely on EWS, eg https://social.msdn.microsoft.com/Forums/en-US/aec6c998-f304-439c-9fa7-27bb9a4c4b45/problem-accessing-folders-in-another-mailbox?forum=exchangesvrdevelopment - such examples work for 2007+, the Exchange server I have to target is 2003. 到目前为止,我发现的解决方案都依赖EWS,例如https://social.msdn.microsoft.com/Forums/en-US/aec6c998-f304-439c-9fa7-27bb9a4c4b45/problem-accessing-folders-in-another-mailbox ?forum = exchangesvrdevelopment-这样的示例适用于2007年以上,我要定位的Exchange服务器是2003年。

Other examples are outlook Addins. 其他示例是Outlook Addins。

I need a standalone solution (an executable) that each time it runs, it's creating contacts from a DB into a particular subfolder under user's Contacts folder. 我需要一个独立的解决方案(可执行文件),该解决方案每次运行时,都会将数据库中的联系人创建到用户的“联系人”文件夹下的特定子文件夹中。

I also searched for some MAPI code samples (.Net) without much luck. 我也没有太多运气就搜索了一些MAPI代码示例(.Net)。

Could you please provide code (either VB.NET or C#) illustrating how to access a private mailbox Contacts folder (or a subfolder), to write a new contact item there? 您能否提供代码(VB.NET或C#)来说明如何访问私有邮箱的“联系人”文件夹(或子文件夹),以便在其中写入新的联系人项?

If you're trying to do it from .Net, then you probably need to use the Outlook object as described in the conclusion to the Using MAPI to Create Outlook 2007 Items article on MSDN. 如果尝试从.Net执行此操作,则可能需要使用MSDN上“使用MAPI创建Outlook 2007项目的文章”结论中所述的Outlook对象。 CDO and RDO are meant to be used with VBscript and other unmanaged code. CDO和RDO旨在与VBscript和其他非托管代码一起使用。

Using this method, you're using C# to leverage Outlook 2007 (or better) automation in the given mailbox. 使用此方法,您正在使用C#来利用给定邮箱中的Outlook 2007(或更好)自动化。 Yes, it would require an account that would have appropriate access permissions to the target mailbox, and you'd have to iterate through the mailboxes and navigate the folder tree yourself. 是的,它需要一个对目标邮箱具有适当访问权限的帐户,并且您必须遍历邮箱并自己导航文件夹树。

The example they give is this: 他们给出的示例是这样的:

private void AddContact()
{
    try
    {
        Outlook.ContactItem oContact =
            Application.CreateItem(
            Outlook.OlItemType.olContactItem)
            as Outlook.ContactItem;
        oContact.FirstName = "Jacqueline";
        oContact.LastName = "Haddad";
        oContact.Initials = "J.H.";
        oContact.CompanyName = "Microsoft";
        oContact.Email1Address = "someone@example.com";
        oContact.Email1AddressType = "SMTP";
        oContact.Email1DisplayName =
            "Jacqueline Haddad (someone@example.com)";
        oContact.BusinessAddressStreet = "1 Microsoft Way";
        oContact.BusinessAddressCity = "Redmond";
        oContact.BusinessAddressState = "WA";
        oContact.BusinessAddressPostalCode = "95802";
        oContact.BusinessAddressCountry = "USA";
        oContact.BusinessTelephoneNumber = "800-555-1212";
        oContact.WebPage = "http://www.codeplex.com/mfcmapi";
        oContact.Body = "This is a sample note.";
        oContact.Save();
    }
    catch (Exception ex)
    {
        Debug.WriteLine(ex.Message);
    }
}

[Promoted from a comment] [从评论中推荐]

Entirely stand-alone is going to be problematic, but have a look at Redemption Data Objects which exposes the CDO/RDO mechanism used by outlook. 完全独立是有问题的,但请看一下“ 兑换数据对象” ,它揭示了Outlook使用的CDO / RDO机制。 It does require Outlook to be installed, but doesn't require it to be running (it uses the libraries, but doesn't work by automating Outlook). 它确实需要安装Outlook,但不需要运行它(它使用库,但不能通过自动执行Outlook工作)。

We recently started using RDO and are getting much better performance than EWS. 我们最近开始使用RDO,并且获得了比EWS更好的性能。

Even if you don't use that, grab a (free) copy of OutlookSpy by the same company. 即使您不使用它,也可以获取同一公司的(免费) OutlookSpy副本。 It will expose a lot of info about how Exchange works internally, especially the data structures is uses (It adds a toolbar to Outlook, it's not stand alone). 它将公开很多有关Exchange内部工作方式的信息,尤其是数据结构的用途(它向Outlook添加了工具栏,并不是一个独立的工具)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM