none
Cannot access extended property (EWS) in Outlook 2010 RRS feed

  • Question

  • Hi all,

    Additional Information:

    • Visual Studio 2010 version 10.0.40219.1 SP1
    • Outlook 2010 version 14.0.6112.5000 (32-bit)
    • Exchange Server 2010

    I'm trying to send a mail with a user property by making use of EWS. Then in the mail client (which is Outlook), I'm trying to read the user property. Needless to say, this is not working, hence the reason for this post.

    This is my code thus far:

    EWS Code

            static void Main(string[] args)
            {
                ServicePointManager.ServerCertificateValidationCallback =
                        delegate(Object obj, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
                        {
                            return true;
                        };
    
                ExchangeServiceBinding ews = new ExchangeServiceBinding();
                ews.Credentials = new NetworkCredential("user", "password", "domain");
                ews.Url = "https://exchangeserver.local/EWS/Exchange.asmx";
    
                MessageType emailMessage = new MessageType();
    
                emailMessage.ToRecipients = new EmailAddressType[1];
                emailMessage.ToRecipients[0] = new EmailAddressType();
                emailMessage.ToRecipients[0].EmailAddress = "richard@domain.com"; //Currently there is only one recipient
    
                emailMessage.From = new SingleRecipientType();  //set up a single sender
                emailMessage.From.Item = new EmailAddressType();
                emailMessage.From.Item.EmailAddress = "richard@domain.com";
    
                emailMessage.Subject = "Subject Goes Here";
    
                emailMessage.Body = new BodyType();
                emailMessage.Body.BodyType1 = BodyTypeType.Text; //specify HTML or plain Text
                emailMessage.Body.Value = "Body Goes Here";
    
                emailMessage.ExtendedProperty = new ExtendedPropertyType[1];
    
                PathToExtendedFieldType setMyProperty = new PathToExtendedFieldType();
                setMyProperty.DistinguishedPropertySetId = DistinguishedPropertySetType.PublicStrings;
                setMyProperty.DistinguishedPropertySetIdSpecified = true;
                setMyProperty.PropertyName = "myCustomProp";
                setMyProperty.PropertyType = MapiPropertyTypeType.String;
    
                emailMessage.ExtendedProperty[0] = new ExtendedPropertyType();
                emailMessage.ExtendedProperty[0].ExtendedFieldURI = setMyProperty;
                emailMessage.ExtendedProperty[0].Item = "foo bar";
    
                CreateItemType emailToSave = new CreateItemType();
                emailToSave.Items = new NonEmptyArrayOfAllItemsType();
                emailToSave.Items.Items = new ItemType[1];
                emailToSave.Items.Items[0] = emailMessage;
                emailToSave.MessageDisposition = MessageDispositionType.SendAndSaveCopy;
                emailToSave.MessageDispositionSpecified = true;
    
                CreateItemResponseType response = ews.CreateItem(emailToSave);
    
                // Get the response messages.
                ResponseMessageType[] rmta = response.ResponseMessages.Items;
    
                Console.WriteLine("Mail has been sent");
                Console.ReadLine();
            }

    Outlook Form Region Code:

        partial class FormRegion1
        {
            private void button1_Click(object sender, EventArgs e)
            {
                UserProperties userProperties = ((MailItem)this.OutlookItem).UserProperties;
                System.Windows.Forms.MessageBox.Show(userProperties.Count.ToString());
    
                if (((MailItem)this.OutlookItem).UserProperties.Count > 0)
                {
                    System.Windows.Forms.MessageBox.Show(((MailItem)this.OutlookItem).UserProperties["myCustomProp"].Value);
                }
            }
        }

    The issue is that I cannot access the user property created in EWS within the Outlook client. 

    Any suggestions? 

    Many thanks in advance!


    GMT + 2:00 South Africa
    Kind Regards
    Richard

    Friday, March 2, 2012 3:01 PM

Answers

  • It looks to me like you just created a MAPI named property in PS_PUBLIC_STRINGS, but that doesn't necessarily create an Outlook UserProperty. Can you see the property at all on the item using a MAPI viewer such as OutlookSpy or MFCMAPI? If so you could get at it using PropertyAccessor. EWS knows nothing about Outlook or Outlook UserProperties.
     

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "RGA Bailey" <=?utf-8?B?UkdBIEJhaWxleQ==?=> wrote in message news:0d96146d-c144-4c5d-9fea-044879a1bcdc...

    Hi all,

    Additional Information:

    • Visual Studio 2010 version 10.0.40219.1 SP1
    • Outlook 2010 version 14.0.6112.5000 (32-bit)
    • Exchange Server 2010

    I'm trying to send a mail with a user property by making use of EWS. Then in the mail client (which is Outlook), I'm trying to read the user property. Needless to say, this is not working, hence the reason for this post.

    This is my code thus far:

    EWS Code

            static void Main(string[] args)
            {
                ServicePointManager.ServerCertificateValidationCallback =
                        delegate(Object obj, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
                        {
                            return true;
                        };
    
                ExchangeServiceBinding ews = new ExchangeServiceBinding();
                ews.Credentials = new NetworkCredential("user", "password", "domain");
                ews.Url = "https://exchangeserver.local/EWS/Exchange.asmx";
    
                MessageType emailMessage = new MessageType();
    
                emailMessage.ToRecipients = new EmailAddressType[1];
                emailMessage.ToRecipients[0] = new EmailAddressType();
                emailMessage.ToRecipients[0].EmailAddress = "richard@domain.com"; //Currently there is only one recipient
    
                emailMessage.From = new SingleRecipientType();  //set up a single sender
                emailMessage.From.Item = new EmailAddressType();
                emailMessage.From.Item.EmailAddress = "richard@domain.com";
    
                emailMessage.Subject = "Subject Goes Here";
    
                emailMessage.Body = new BodyType();
                emailMessage.Body.BodyType1 = BodyTypeType.Text; //specify HTML or plain Text
                emailMessage.Body.Value = "Body Goes Here";
    
                emailMessage.ExtendedProperty = new ExtendedPropertyType[1];
    
                PathToExtendedFieldType setMyProperty = new PathToExtendedFieldType();
                setMyProperty.DistinguishedPropertySetId = DistinguishedPropertySetType.PublicStrings;
                setMyProperty.DistinguishedPropertySetIdSpecified = true;
                setMyProperty.PropertyName = "myCustomProp";
                setMyProperty.PropertyType = MapiPropertyTypeType.String;
    
                emailMessage.ExtendedProperty[0] = new ExtendedPropertyType();
                emailMessage.ExtendedProperty[0].ExtendedFieldURI = setMyProperty;
                emailMessage.ExtendedProperty[0].Item = "foo bar";
    
                CreateItemType emailToSave = new CreateItemType();
                emailToSave.Items = new NonEmptyArrayOfAllItemsType();
                emailToSave.Items.Items = new ItemType[1];
                emailToSave.Items.Items[0] = emailMessage;
                emailToSave.MessageDisposition = MessageDispositionType.SendAndSaveCopy;
                emailToSave.MessageDispositionSpecified = true;
    
                CreateItemResponseType response = ews.CreateItem(emailToSave);
    
                // Get the response messages.
                ResponseMessageType[] rmta = response.ResponseMessages.Items;
    
                Console.WriteLine("Mail has been sent");
                Console.ReadLine();
            }

    Outlook Form Region Code:

        partial class FormRegion1
        {
            private void button1_Click(object sender, EventArgs e)
            {
                UserProperties userProperties = ((MailItem)this.OutlookItem).UserProperties;
                System.Windows.Forms.MessageBox.Show(userProperties.Count.ToString());
    
                if (((MailItem)this.OutlookItem).UserProperties.Count > 0)
                {
                    System.Windows.Forms.MessageBox.Show(((MailItem)this.OutlookItem).UserProperties["myCustomProp"].Value);
                }
            }
        }

    The issue is that I cannot access the user property created in EWS within the Outlook client. 

    Any suggestions? 

    Many thanks in advance!


    GMT + 2:00 South Africa
    Kind Regards
    Richard


    Ken Slovak MVP - Outlook
    • Marked as answer by RGA Bailey Friday, March 2, 2012 7:39 PM
    Friday, March 2, 2012 3:08 PM
    Moderator

All replies

  • It looks to me like you just created a MAPI named property in PS_PUBLIC_STRINGS, but that doesn't necessarily create an Outlook UserProperty. Can you see the property at all on the item using a MAPI viewer such as OutlookSpy or MFCMAPI? If so you could get at it using PropertyAccessor. EWS knows nothing about Outlook or Outlook UserProperties.
     

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "RGA Bailey" <=?utf-8?B?UkdBIEJhaWxleQ==?=> wrote in message news:0d96146d-c144-4c5d-9fea-044879a1bcdc...

    Hi all,

    Additional Information:

    • Visual Studio 2010 version 10.0.40219.1 SP1
    • Outlook 2010 version 14.0.6112.5000 (32-bit)
    • Exchange Server 2010

    I'm trying to send a mail with a user property by making use of EWS. Then in the mail client (which is Outlook), I'm trying to read the user property. Needless to say, this is not working, hence the reason for this post.

    This is my code thus far:

    EWS Code

            static void Main(string[] args)
            {
                ServicePointManager.ServerCertificateValidationCallback =
                        delegate(Object obj, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
                        {
                            return true;
                        };
    
                ExchangeServiceBinding ews = new ExchangeServiceBinding();
                ews.Credentials = new NetworkCredential("user", "password", "domain");
                ews.Url = "https://exchangeserver.local/EWS/Exchange.asmx";
    
                MessageType emailMessage = new MessageType();
    
                emailMessage.ToRecipients = new EmailAddressType[1];
                emailMessage.ToRecipients[0] = new EmailAddressType();
                emailMessage.ToRecipients[0].EmailAddress = "richard@domain.com"; //Currently there is only one recipient
    
                emailMessage.From = new SingleRecipientType();  //set up a single sender
                emailMessage.From.Item = new EmailAddressType();
                emailMessage.From.Item.EmailAddress = "richard@domain.com";
    
                emailMessage.Subject = "Subject Goes Here";
    
                emailMessage.Body = new BodyType();
                emailMessage.Body.BodyType1 = BodyTypeType.Text; //specify HTML or plain Text
                emailMessage.Body.Value = "Body Goes Here";
    
                emailMessage.ExtendedProperty = new ExtendedPropertyType[1];
    
                PathToExtendedFieldType setMyProperty = new PathToExtendedFieldType();
                setMyProperty.DistinguishedPropertySetId = DistinguishedPropertySetType.PublicStrings;
                setMyProperty.DistinguishedPropertySetIdSpecified = true;
                setMyProperty.PropertyName = "myCustomProp";
                setMyProperty.PropertyType = MapiPropertyTypeType.String;
    
                emailMessage.ExtendedProperty[0] = new ExtendedPropertyType();
                emailMessage.ExtendedProperty[0].ExtendedFieldURI = setMyProperty;
                emailMessage.ExtendedProperty[0].Item = "foo bar";
    
                CreateItemType emailToSave = new CreateItemType();
                emailToSave.Items = new NonEmptyArrayOfAllItemsType();
                emailToSave.Items.Items = new ItemType[1];
                emailToSave.Items.Items[0] = emailMessage;
                emailToSave.MessageDisposition = MessageDispositionType.SendAndSaveCopy;
                emailToSave.MessageDispositionSpecified = true;
    
                CreateItemResponseType response = ews.CreateItem(emailToSave);
    
                // Get the response messages.
                ResponseMessageType[] rmta = response.ResponseMessages.Items;
    
                Console.WriteLine("Mail has been sent");
                Console.ReadLine();
            }

    Outlook Form Region Code:

        partial class FormRegion1
        {
            private void button1_Click(object sender, EventArgs e)
            {
                UserProperties userProperties = ((MailItem)this.OutlookItem).UserProperties;
                System.Windows.Forms.MessageBox.Show(userProperties.Count.ToString());
    
                if (((MailItem)this.OutlookItem).UserProperties.Count > 0)
                {
                    System.Windows.Forms.MessageBox.Show(((MailItem)this.OutlookItem).UserProperties["myCustomProp"].Value);
                }
            }
        }

    The issue is that I cannot access the user property created in EWS within the Outlook client. 

    Any suggestions? 

    Many thanks in advance!


    GMT + 2:00 South Africa
    Kind Regards
    Richard


    Ken Slovak MVP - Outlook
    • Marked as answer by RGA Bailey Friday, March 2, 2012 7:39 PM
    Friday, March 2, 2012 3:08 PM
    Moderator
  • Hi Ken,

    Many thanks for the reply. I got it working by making use of the following:

            private void button1_Click(object sender, EventArgs e)
            {
                string props = string.Empty;
    
                object myCustomProp = ((MailItem)this.OutlookItem).PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/string/{00020329-0000-0000-C000-000000000046}/myCustomProp/0x0000001F");
                if (functionName != null)
                {
                    props = string.Format("Custom Prop Value: {0}\n", functionName);
                }
    
                System.Windows.Forms.MessageBox.Show(props);
            }

    Kind regards,


    GMT + 2:00 South Africa
    Kind Regards
    Richard

    Friday, March 2, 2012 7:39 PM