/// <summary> /// Generate property value on recipient. /// </summary> /// <param name="userName">Recipient user name.</param> /// <param name="userDN">Recipient user dn.</param> /// <returns>Property array value.</returns> public static TaggedPropertyValue[] GenerateRecipientPropertiesBlock(string userName, string userDN) { TaggedPropertyValue[] recipientProperties = new TaggedPropertyValue[4]; // Add PidTagDisplayName recipientProperties[0] = new TaggedPropertyValue(); PropertyTag pidTagDisplayNamePropertyTag = new PropertyTag { PropertyId = (ushort)PropertyId.PidTagDisplayName, PropertyType = (ushort)PropertyType.PtypString }; recipientProperties[0].PropertyTag = pidTagDisplayNamePropertyTag; recipientProperties[0].Value = Encoding.Unicode.GetBytes(userName + "\0"); // Add PidTagEmailAddress recipientProperties[1] = new TaggedPropertyValue(); PropertyTag pidTagEmailAddressPropertyTag = new PropertyTag { PropertyId = (ushort)PropertyId.PidTagEmailAddress, PropertyType = (ushort)PropertyType.PtypString }; recipientProperties[1].PropertyTag = pidTagEmailAddressPropertyTag; recipientProperties[1].Value = Encoding.Unicode.GetBytes(userDN + "\0"); // Add PidTagRecipientType recipientProperties[2] = new TaggedPropertyValue(); PropertyTag pidTagRecipientTypePropertyTag = new PropertyTag { PropertyId = (ushort)PropertyId.PidTagRecipientType, PropertyType = (ushort)PropertyType.PtypInteger32 }; recipientProperties[2].PropertyTag = pidTagRecipientTypePropertyTag; recipientProperties[2].Value = BitConverter.GetBytes(0x00000001); AddressBookEntryID addressBookEntryID = new AddressBookEntryID(userDN); // Add PidTagEntryID recipientProperties[3] = new TaggedPropertyValue(); PropertyTag pidTagEntryIDPropertyTag = new PropertyTag { PropertyId = (ushort)PropertyId.PidTagEntryId, PropertyType = (ushort)PropertyType.PtypBinary }; recipientProperties[3].PropertyTag = pidTagEntryIDPropertyTag; recipientProperties[3].Value = Common.AddInt16LengthBeforeBinaryArray(addressBookEntryID.Serialize()); return recipientProperties; }
/// <summary> /// Submit a message to the server /// </summary> /// <param name="mailTo">The user name of the recipient</param> /// <param name="mailToUserDN">The userDN of the recipient</param> /// <param name="subject">The subject of the mail</param> /// <param name="addedProperties">The added properties of the mail</param> /// <returns>Return code of the message delivering</returns> public uint DeliverMessageToTriggerRule(string mailTo, string mailToUserDN, string subject, TaggedPropertyValue[] addedProperties) { RopCreateMessageResponse createMsgRes; uint msgHandle = this.OxoruleAdapter.RopCreateMessage(outBoxFolderHandle, outBoxFolderID, 0, out createMsgRes); TaggedPropertyValue[] clientSpecificProperties = new TaggedPropertyValue[1]; clientSpecificProperties[0] = new TaggedPropertyValue(); PropertyTag propertyTag = new PropertyTag { PropertyId = (ushort)PropertyId.PidTagSubject, PropertyType = (ushort)PropertyType.PtypString }; clientSpecificProperties[0].PropertyTag = propertyTag; clientSpecificProperties[0].Value = Encoding.Unicode.GetBytes(subject + "\0"); this.OxoruleAdapter.RopSetProperties(msgHandle, clientSpecificProperties); if (addedProperties != null && addedProperties.Length > 0) { this.OxoruleAdapter.RopSetProperties(msgHandle, addedProperties); } #region recipientColumns, PropertyTag[] sampleRecipientColumns // The following sample data is from MS-OXCMSG 4.7.1 PropertyTag[] sampleRecipientColumns = new PropertyTag[12]; PropertyTag tag = new PropertyTag { PropertyId = (ushort)PropertyId.PidTagObjectType, PropertyType = (ushort)PropertyType.PtypInteger32 }; // PidTagObjectType sampleRecipientColumns[0] = tag; // PidTagDisplayType tag.PropertyId = (ushort)PropertyId.PidTagDisplayType; tag.PropertyType = (ushort)PropertyType.PtypInteger32; sampleRecipientColumns[1] = tag; // PidTagAddressBookDisplayNamePrintable tag.PropertyId = (ushort)PropertyId.PidTagAddressBookDisplayNamePrintable; tag.PropertyType = (ushort)PropertyType.PtypString; sampleRecipientColumns[2] = tag; // PidTagSmtpAddress tag.PropertyId = (ushort)PropertyId.PidTagSmtpAddress; tag.PropertyType = (ushort)PropertyType.PtypString; sampleRecipientColumns[3] = tag; // PidTagSendInternetEncoding tag.PropertyId = (ushort)PropertyId.PidTagSendInternetEncoding; tag.PropertyType = (ushort)PropertyType.PtypInteger32; sampleRecipientColumns[4] = tag; // PidTagDisplayTypeEx tag.PropertyId = (ushort)PropertyId.PidTagDisplayTypeEx; tag.PropertyType = (ushort)PropertyType.PtypInteger32; sampleRecipientColumns[5] = tag; // PidTagRecipientDisplayName tag.PropertyId = (ushort)PropertyId.PidTagRecipientDisplayName; tag.PropertyType = (ushort)PropertyType.PtypString; sampleRecipientColumns[6] = tag; // PidTagRecipientFlags tag.PropertyId = (ushort)PropertyId.PidTagRecipientFlags; tag.PropertyType = (ushort)PropertyType.PtypInteger32; sampleRecipientColumns[7] = tag; // PidTagRecipientTrackStatus tag.PropertyId = (ushort)PropertyId.PidTagRecipientTrackStatus; tag.PropertyType = (ushort)PropertyType.PtypInteger32; sampleRecipientColumns[8] = tag; // PidTagRecipientResourceState tag.PropertyId = (ushort)PropertyId.PidTagRecipientResourceState; tag.PropertyType = (ushort)PropertyType.PtypInteger32; sampleRecipientColumns[9] = tag; // PidTagRecipientOrder tag.PropertyId = (ushort)PropertyId.PidTagRecipientOrder; tag.PropertyType = (ushort)PropertyType.PtypInteger32; sampleRecipientColumns[10] = tag; // PidTagRecipientEntryId tag.PropertyId = (ushort)PropertyId.PidTagRecipientEntryId; tag.PropertyType = (ushort)PropertyType.PtypBinary; sampleRecipientColumns[11] = tag; #endregion #region Configure a StandardPropertyRow: propertyRow PropertyValue[] propertyValueArray = new PropertyValue[12]; for (int i = 0; i < propertyValueArray.Length; i++) { propertyValueArray[i] = new PropertyValue(); } // PidTagObjectType propertyValueArray[0].Value = BitConverter.GetBytes(0x00000006); // PidTagDisplayType propertyValueArray[1].Value = BitConverter.GetBytes(0x00000000); // PidTagAddressBookDisplayNamePrintable propertyValueArray[2].Value = Encoding.Unicode.GetBytes(mailTo + "\0"); // PidTagSmtpAddress propertyValueArray[3].Value = Encoding.Unicode.GetBytes(mailTo + "@" + this.Domain + "\0"); // PidTagSendInternetEncoding propertyValueArray[4].Value = BitConverter.GetBytes(0x00000000); // PidTagDisplayTypeEx propertyValueArray[5].Value = BitConverter.GetBytes(0x40000000); // PidTagRecipientDisplayName propertyValueArray[6].Value = Encoding.Unicode.GetBytes(mailTo + "\0"); // PidTagRecipientFlags propertyValueArray[7].Value = BitConverter.GetBytes(0x00000001); // PidTagRecipientTrackStatus propertyValueArray[8].Value = BitConverter.GetBytes(0x00000000); // PidTagRecipientResourceState propertyValueArray[9].Value = BitConverter.GetBytes(0x00000000); // PidTagRecipientOrder propertyValueArray[10].Value = BitConverter.GetBytes(0x00000000); AddressBookEntryID addressBookEntryID = new AddressBookEntryID(mailToUserDN); propertyValueArray[11].Value = Common.AddInt16LengthBeforeBinaryArray(addressBookEntryID.Serialize()); List <PropertyValue> propertyValues = new List <PropertyValue>(); for (int i = 0; i < propertyValueArray.Length; i++) { propertyValues.Add(propertyValueArray[i]); } PropertyRow propertyRow = new PropertyRow { Flag = 0x01, PropertyValues = propertyValues }; #endregion RecipientRow recipientRow = new RecipientRow { RecipientFlags = 0x065B, DisplayName = Encoding.Unicode.GetBytes(mailTo + "\0"), EmailAddress = Encoding.Unicode.GetBytes(mailTo + "@" + this.Domain + "\0"), SimpleDisplayName = Encoding.Unicode.GetBytes(mailTo + "\0"), RecipientColumnCount = 0x000C, RecipientProperties = propertyRow }; ModifyRecipientRow modifyRecipientRow = new ModifyRecipientRow { RowId = 0x00000000, RecipientType = 0x01, RecipientRowSize = (ushort)recipientRow.Size(), RecptRow = recipientRow.Serialize() }; ModifyRecipientRow[] sampleModifyRecipientRows = new ModifyRecipientRow[1]; sampleModifyRecipientRows[0] = modifyRecipientRow; this.OxoruleAdapter.RopModifyRecipients(msgHandle, sampleRecipientColumns, sampleModifyRecipientRows); this.OxoruleAdapter.RopSaveChangesMessage(msgHandle); RopSubmitMessageResponse submitMsgRes = this.OxoruleAdapter.RopSubmitMessage(msgHandle, 0); return(submitMsgRes.ReturnValue); }
/// <summary> /// Submit a message to the server /// </summary> /// <param name="mailTo">The user name of the recipient</param> /// <param name="mailToUserDN">The userDN of the recipient</param> /// <param name="subject">The subject of the mail</param> /// <param name="addedProperties">The added properties of the mail</param> /// <returns>Return code of the message delivering</returns> public uint DeliverMessageToTriggerRule(string mailTo, string mailToUserDN, string subject, TaggedPropertyValue[] addedProperties) { RopCreateMessageResponse createMsgRes; uint msgHandle = this.OxoruleAdapter.RopCreateMessage(outBoxFolderHandle, outBoxFolderID, 0, out createMsgRes); TaggedPropertyValue[] clientSpecificProperties = new TaggedPropertyValue[1]; clientSpecificProperties[0] = new TaggedPropertyValue(); PropertyTag propertyTag = new PropertyTag { PropertyId = (ushort)PropertyId.PidTagSubject, PropertyType = (ushort)PropertyType.PtypString }; clientSpecificProperties[0].PropertyTag = propertyTag; clientSpecificProperties[0].Value = Encoding.Unicode.GetBytes(subject + "\0"); this.OxoruleAdapter.RopSetProperties(msgHandle, clientSpecificProperties); if (addedProperties != null && addedProperties.Length > 0) { this.OxoruleAdapter.RopSetProperties(msgHandle, addedProperties); } #region recipientColumns, PropertyTag[] sampleRecipientColumns // The following sample data is from MS-OXCMSG 4.7.1 PropertyTag[] sampleRecipientColumns = new PropertyTag[12]; PropertyTag tag = new PropertyTag { PropertyId = (ushort)PropertyId.PidTagObjectType, PropertyType = (ushort)PropertyType.PtypInteger32 }; // PidTagObjectType sampleRecipientColumns[0] = tag; // PidTagDisplayType tag.PropertyId = (ushort)PropertyId.PidTagDisplayType; tag.PropertyType = (ushort)PropertyType.PtypInteger32; sampleRecipientColumns[1] = tag; // PidTagAddressBookDisplayNamePrintable tag.PropertyId = (ushort)PropertyId.PidTagAddressBookDisplayNamePrintable; tag.PropertyType = (ushort)PropertyType.PtypString; sampleRecipientColumns[2] = tag; // PidTagSmtpAddress tag.PropertyId = (ushort)PropertyId.PidTagSmtpAddress; tag.PropertyType = (ushort)PropertyType.PtypString; sampleRecipientColumns[3] = tag; // PidTagSendInternetEncoding tag.PropertyId = (ushort)PropertyId.PidTagSendInternetEncoding; tag.PropertyType = (ushort)PropertyType.PtypInteger32; sampleRecipientColumns[4] = tag; // PidTagDisplayTypeEx tag.PropertyId = (ushort)PropertyId.PidTagDisplayTypeEx; tag.PropertyType = (ushort)PropertyType.PtypInteger32; sampleRecipientColumns[5] = tag; // PidTagRecipientDisplayName tag.PropertyId = (ushort)PropertyId.PidTagRecipientDisplayName; tag.PropertyType = (ushort)PropertyType.PtypString; sampleRecipientColumns[6] = tag; // PidTagRecipientFlags tag.PropertyId = (ushort)PropertyId.PidTagRecipientFlags; tag.PropertyType = (ushort)PropertyType.PtypInteger32; sampleRecipientColumns[7] = tag; // PidTagRecipientTrackStatus tag.PropertyId = (ushort)PropertyId.PidTagRecipientTrackStatus; tag.PropertyType = (ushort)PropertyType.PtypInteger32; sampleRecipientColumns[8] = tag; // PidTagRecipientResourceState tag.PropertyId = (ushort)PropertyId.PidTagRecipientResourceState; tag.PropertyType = (ushort)PropertyType.PtypInteger32; sampleRecipientColumns[9] = tag; // PidTagRecipientOrder tag.PropertyId = (ushort)PropertyId.PidTagRecipientOrder; tag.PropertyType = (ushort)PropertyType.PtypInteger32; sampleRecipientColumns[10] = tag; // PidTagRecipientEntryId tag.PropertyId = (ushort)PropertyId.PidTagRecipientEntryId; tag.PropertyType = (ushort)PropertyType.PtypBinary; sampleRecipientColumns[11] = tag; #endregion #region Configure a StandardPropertyRow: propertyRow PropertyValue[] propertyValueArray = new PropertyValue[12]; for (int i = 0; i < propertyValueArray.Length; i++) { propertyValueArray[i] = new PropertyValue(); } // PidTagObjectType propertyValueArray[0].Value = BitConverter.GetBytes(0x00000006); // PidTagDisplayType propertyValueArray[1].Value = BitConverter.GetBytes(0x00000000); // PidTagAddressBookDisplayNamePrintable propertyValueArray[2].Value = Encoding.Unicode.GetBytes(mailTo + "\0"); // PidTagSmtpAddress propertyValueArray[3].Value = Encoding.Unicode.GetBytes(mailTo + "@" + this.Domain + "\0"); // PidTagSendInternetEncoding propertyValueArray[4].Value = BitConverter.GetBytes(0x00000000); // PidTagDisplayTypeEx propertyValueArray[5].Value = BitConverter.GetBytes(0x40000000); // PidTagRecipientDisplayName propertyValueArray[6].Value = Encoding.Unicode.GetBytes(mailTo + "\0"); // PidTagRecipientFlags propertyValueArray[7].Value = BitConverter.GetBytes(0x00000001); // PidTagRecipientTrackStatus propertyValueArray[8].Value = BitConverter.GetBytes(0x00000000); // PidTagRecipientResourceState propertyValueArray[9].Value = BitConverter.GetBytes(0x00000000); // PidTagRecipientOrder propertyValueArray[10].Value = BitConverter.GetBytes(0x00000000); AddressBookEntryID addressBookEntryID = new AddressBookEntryID(mailToUserDN); propertyValueArray[11].Value = Common.AddInt16LengthBeforeBinaryArray(addressBookEntryID.Serialize()); List<PropertyValue> propertyValues = new List<PropertyValue>(); for (int i = 0; i < propertyValueArray.Length; i++) { propertyValues.Add(propertyValueArray[i]); } PropertyRow propertyRow = new PropertyRow { Flag = 0x01, PropertyValues = propertyValues }; #endregion RecipientRow recipientRow = new RecipientRow { RecipientFlags = 0x065B, DisplayName = Encoding.Unicode.GetBytes(mailTo + "\0"), EmailAddress = Encoding.Unicode.GetBytes(mailTo + "@" + this.Domain + "\0"), SimpleDisplayName = Encoding.Unicode.GetBytes(mailTo + "\0"), RecipientColumnCount = 0x000C, RecipientProperties = propertyRow }; ModifyRecipientRow modifyRecipientRow = new ModifyRecipientRow { RowId = 0x00000000, RecipientType = 0x01, RecipientRowSize = (ushort)recipientRow.Size(), RecptRow = recipientRow.Serialize() }; ModifyRecipientRow[] sampleModifyRecipientRows = new ModifyRecipientRow[1]; sampleModifyRecipientRows[0] = modifyRecipientRow; this.OxoruleAdapter.RopModifyRecipients(msgHandle, sampleRecipientColumns, sampleModifyRecipientRows); this.OxoruleAdapter.RopSaveChangesMessage(msgHandle); RopSubmitMessageResponse submitMsgRes = this.OxoruleAdapter.RopSubmitMessage(msgHandle, 0); return submitMsgRes.ReturnValue; }