Exemplo n.º 1
0
        public static void Run()
        {
            // Set Exchange Server web service URL, Username, password, domain information
            string mailboxURI = "https://ex2010/ews/exchange.asmx";
            string username   = "******";
            string password   = "******";
            string domain     = "ex2010.local";

            //ExStart: WorkingWithExtendedAttributesOfMessages
            // Connect to the Exchange Server
            NetworkCredential credential = new NetworkCredential(username, password, domain);
            IEWSClient        client     = EWSClient.GetEWSClient(mailboxURI, credential);
            {
                try
                {
                    //Create a new Property
                    PidNamePropertyDescriptor pd = new PidNamePropertyDescriptor(
                        "MyTestProp",
                        PropertyDataType.String,
                        KnownPropertySets.PublicStrings);
                    string value = "MyTestPropValue";

                    //Create a message
                    MapiMessage message = new MapiMessage(
                        "*****@*****.**",
                        "*****@*****.**",
                        "EMAILNET-38844 - " + Guid.NewGuid().ToString(),
                        "EMAILNET-38844 EWS: Support for create, retrieve and update Extended Attributes for Emails");

                    //Set property on the message
                    message.SetProperty(pd, value);

                    //append the message to server
                    string uri = client.AppendMessage(message);

                    //Fetch the message from server
                    MapiMessage mapiMessage = client.FetchMapiMessage(uri, new PropertyDescriptor[] { pd });

                    //Retreive the value from Message
                    string fetchedValue = mapiMessage.NamedProperties[pd].GetString();
                }
                finally
                {
                }
            }
            //ExEnd: WorkingWithExtendedAttributesOfMessages
        }
        public static void Run()
        {
            //ExStart: RetreiveExtAttributesForCalendarItems
            IEWSClient client = EWSClient.GetEWSClient("https://exchange.office365.com/Exchange.asmx", "username", "password");

            //Fetch all calendars from Exchange calendar's folder
            string[] uriList = client.ListItems(client.MailboxInfo.CalendarUri);

            //Define the Extended Attribute Property Descriptor for searching purpose
            //In this case, we have a K1 Long named property for Calendar item
            PropertyDescriptor propertyDescriptor = new PidNamePropertyDescriptor("K1", PropertyDataType.Integer32, new Guid("00020329-0000-0000-C000-000000000046"));

            //Fetch calendars that have the custom property
            IList <MapiCalendar> mapiCalendarList = client.FetchMapiCalendar(uriList, new PropertyDescriptor[] { propertyDescriptor });

            foreach (MapiCalendar cal in mapiCalendarList)
            {
                foreach (MapiNamedProperty namedProperty in cal.NamedProperties.Values)
                {
                    Console.WriteLine(namedProperty.NameId + " = " + namedProperty.GetInt32());
                }
            }
            //ExEnd: RetreiveExtAttributesForCalendarItems
        }