EWS托管API-日历共享请求问题

时间:2019-02-04 12:54:40

标签: c# outlook calendar request exchangewebservices

我想向特殊用户发送共享请求,以访问其日历项目。收到此消息后,用户可以接受或拒绝我的请求。 经过2天的查询和编码后的一个小示例,我被困在正确的参数(如PidTagMessageClass之类的ExtendedPropertyDefinition等)上。

请查看以下相关代码段:

public void SendMessage()
{
    byte[] binInitiatorEntryId = Converter.HexStringToByteArray(this.MailboxFunctions.GetIntiatorEntryID(this.Service));

    // This is the Guid of the Sharing Provider in Exchange, and it's value does not change
    Guid PropertySetSharing = new Guid("{AEF00600-0000-0000-C000-000000000046}");

    // Even though I don't think setting this property is mandatory, 
    // it just seemed like the right thing to do and it works so I \
    // ain't messin with it!                                        
    byte[] byteSharingProviderGuid = PropertySetSharing.ToByteArray();

    // Create a new message
    EmailMessage invitationRequest = new EmailMessage(this.Service);
    invitationRequest.Subject = "Sharing request: 'Calendar'";
    invitationRequest.Body = "Sent by Exchange Administrator on behalf of user";
    invitationRequest.From = "sender@mail.com";
    invitationRequest.Culture = "us-US";
    invitationRequest.Sensitivity = Sensitivity.Normal;
    invitationRequest.Sender = "/O=EXCHANGELABS/OU=EXCHANGE ADMINISTRATIVE GROUP (FXDICOHF11SPDLT)/CN=RECIPIENTS/CN=CAA2C1E7A3934797A8258CGG42B337D0-THER";
    invitationRequest.ItemClass = "IPM.Sharing"; /* Constant Required Value [MS-ProtocolSpec] */

    ExtendedPropertyDefinition PidTagMessageClass = new ExtendedPropertyDefinition(0x001A, MapiPropertyType.String);
    invitationRequest.SetExtendedProperty(PidTagMessageClass, "IPM.Sharing"); /* Constant Required Value [MS-ProtocolSpec] */

    ExtendedPropertyDefinition PidNameContentClass = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.InternetHeaders, "Content-Class", MapiPropertyType.String);
    invitationRequest.SetExtendedProperty(PidNameContentClass, "Sharing");

    ExtendedPropertyDefinition PidTagNormalizedSubject = new ExtendedPropertyDefinition(0x0E1D, MapiPropertyType.String);
    invitationRequest.SetExtendedProperty(PidTagNormalizedSubject, "Sharing request: 'Calendar'");

    ExtendedPropertyDefinition PidTagSubjectPrefix = new ExtendedPropertyDefinition(0x003D, MapiPropertyType.String);
    invitationRequest.SetExtendedProperty(PidTagSubjectPrefix, " ");

    ExtendedPropertyDefinition PidLidSharingProviderGuid = new ExtendedPropertyDefinition(PropertySetSharing, 0x8243, MapiPropertyType.Binary);
    invitationRequest.SetExtendedProperty(PidLidSharingProviderGuid, byteSharingProviderGuid);

    ExtendedPropertyDefinition PidNameXSharingProviderGuid = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.InternetHeaders, "X-Sharing-Provider-GUID", MapiPropertyType.String);
    invitationRequest.SetExtendedProperty(PidNameXSharingProviderGuid, "AEF0060000000000C000000000000046"); 

    ExtendedPropertyDefinition PidLidSharingProviderName = new ExtendedPropertyDefinition(PropertySetSharing, 0x8244, MapiPropertyType.String);
    invitationRequest.SetExtendedProperty(PidLidSharingProviderName, "Microsoft Exchange"); 

    ExtendedPropertyDefinition PidNameXSharingProviderName = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.InternetHeaders, "X-Sharing-Provider-Name", MapiPropertyType.String);
    invitationRequest.SetExtendedProperty(PidNameXSharingProviderName, "Microsoft Exchange"); 

    ExtendedPropertyDefinition PidLidSharingProviderUrl = new ExtendedPropertyDefinition(PropertySetSharing, 0x8245, MapiPropertyType.String);
    invitationRequest.SetExtendedProperty(PidLidSharingProviderUrl, "http://www.microsoft.com/exchange"); 

    ExtendedPropertyDefinition PidNameXSharingProviderUrl = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.InternetHeaders, "X-Sharing-Provider-URL", MapiPropertyType.String);
    invitationRequest.SetExtendedProperty(PidNameXSharingProviderUrl, "http://www.microsoft.com/exchange"); 

    ExtendedPropertyDefinition PidLidSharingConfigurationUrl = new ExtendedPropertyDefinition(PropertySetSharing, 0x83D0, MapiPropertyType.String);
    invitationRequest.SetExtendedProperty(PidLidSharingConfigurationUrl, " "); 

    ExtendedPropertyDefinition PidNameXSharingConfigUrl = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.InternetHeaders, "X-Sharing-Config-Url", MapiPropertyType.String);
    invitationRequest.SetExtendedProperty(PidNameXSharingConfigUrl, " "); 

    ExtendedPropertyDefinition PidLidSharingFlavor = new ExtendedPropertyDefinition(PropertySetSharing, 0x823D, MapiPropertyType.Integer);
    invitationRequest.SetExtendedProperty(PidLidSharingFlavor, 0x00020500); 

    ExtendedPropertyDefinition PidNameXSharingFlavor = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.InternetHeaders, "X-Sharing-Flavor", MapiPropertyType.String);
    invitationRequest.SetExtendedProperty(PidNameXSharingFlavor, "20500"); 

    ExtendedPropertyDefinition PidLidSharingCapabilities = new ExtendedPropertyDefinition(PropertySetSharing, 0x823C, MapiPropertyType.Integer);
    invitationRequest.SetExtendedProperty(PidLidSharingCapabilities, 0x00040290); 

    // [MS-OXSHARE] 2.2.2.2
    ExtendedPropertyDefinition PidNameXSharingCapabilities = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.InternetHeaders, "X-Sharing-Capabilities", MapiPropertyType.String);
    invitationRequest.SetExtendedProperty(PidNameXSharingCapabilities, "40290"); 

    // [MS-OXSHARE] 2.2.2.10
    ExtendedPropertyDefinition PidLidSharingLocalType = new ExtendedPropertyDefinition(PropertySetSharing, 0x824F, MapiPropertyType.String);
    invitationRequest.SetExtendedProperty(PidLidSharingLocalType, "IPF.Appointment"); 

    // [MS-OXSHARE] 2.2.2.11
    ExtendedPropertyDefinition PidNameXSharingLocalType = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.InternetHeaders, "X-Sharing-Local-Type", MapiPropertyType.String);
    invitationRequest.SetExtendedProperty(PidNameXSharingLocalType, "IPF.Appointment"); 

    // [MS-OXSHARE] 2.2.2.7
    ExtendedPropertyDefinition PidLidSharingInitiatorEntryId = new ExtendedPropertyDefinition(PropertySetSharing, 0x8249, MapiPropertyType.Binary);
    invitationRequest.SetExtendedProperty(PidLidSharingInitiatorEntryId, binInitiatorEntryId); 

    // [MS-OXSHARE] 2.2.2.8
    ExtendedPropertyDefinition PidLidSharingInitiatorName = new ExtendedPropertyDefinition(PropertySetSharing, 0x8029, MapiPropertyType.String);
    invitationRequest.SetExtendedProperty(PidLidSharingInitiatorName, "SENDER"); 

    // [MS-OXSHARE] 2.2.2.9
    ExtendedPropertyDefinition PidLidSharingInitiatorSMTP = new ExtendedPropertyDefinition(PropertySetSharing, 0x8248, MapiPropertyType.String);
    invitationRequest.SetExtendedProperty(PidLidSharingInitiatorSMTP, "sender@mail.com");

    // Add recipient info and send message
    invitationRequest.ToRecipients.Add("receiver@mail.com");
    invitationRequest.SendAndSaveCopy();
}

这是创建消息和发送消息的主要部分。 要了解此问题,我使用了以下链接: https://willcode4foodblog.wordpress.com/2012/04/13/understanding-sharing-invitation-requests-ews-managed-api-1-2-part-1/ http://interoperability.blob.core.windows.net/files/MS-OXSHARE/[MS-OXSHARE].pdf(尤其是“ 4.1发送共享请求”)

问题是创建的消息在Outlook中可见,但无效。 Outlook显示无效消息,并且允许/拒绝显示为灰色。

外面有人有想法甚至解决了同样的问题吗?谢谢!

0 个答案:

没有答案