示例#1
0
        public List<OutlookAppointment> GetCalendarEntries()
        {
            List<OutlookAppointment> appointments = new List<OutlookAppointment>();
            var _service = new Microsoft.Exchange.WebServices.Data.ExchangeService(Microsoft.Exchange.WebServices.Data.ExchangeVersion.Exchange2010_SP1);
            _service.Credentials = new Microsoft.Exchange.WebServices.Data.WebCredentials(Settings.Instance.ExchageUser, Settings.Instance.ExchagePassword);
            _service.Url = new Uri(Settings.Instance.ExchageServerAddress);
            var items = _service.FindItems(Microsoft.Exchange.WebServices.Data.WellKnownFolderName.Calendar, new Microsoft.Exchange.WebServices.Data.ItemView(int.MaxValue));
            foreach (Microsoft.Exchange.WebServices.Data.Appointment appointment in items)
            {
                OutlookAppointment newAppointment = GetOutlookAppointment(appointment, _service);

                appointments.Add(newAppointment);
            }
            return appointments;
        }
示例#2
0
        public List <OutlookAppointment> GetCalendarEntries()
        {
            List <OutlookAppointment> appointments = new List <OutlookAppointment>();
            var _service = new Microsoft.Exchange.WebServices.Data.ExchangeService(Microsoft.Exchange.WebServices.Data.ExchangeVersion.Exchange2010_SP1);

            _service.Credentials = new Microsoft.Exchange.WebServices.Data.WebCredentials(Settings.Instance.ExchageUser, Settings.Instance.ExchagePassword);
            _service.Url         = new Uri(Settings.Instance.ExchageServerAddress);
            var items = _service.FindItems(Microsoft.Exchange.WebServices.Data.WellKnownFolderName.Calendar, new Microsoft.Exchange.WebServices.Data.ItemView(int.MaxValue));

            foreach (Microsoft.Exchange.WebServices.Data.Appointment appointment in items)
            {
                OutlookAppointment newAppointment = GetOutlookAppointment(appointment, _service);

                appointments.Add(newAppointment);
            }
            return(appointments);
        }
        //check if return itemid != "0"
        public static ItemId FindContact(Microsoft.Exchange.WebServices.Data.ExchangeService service, string achternaam, string voornaam, string tussenvoegsel)
        {
            var returnID = new ItemId("0");
            var folders  = new List <FolderId>(1);
            var f_id     = FindFolder(service);

            // Only use the Contacts folder.
            //NameResolutionCollection resolvedNames = service.ResolveName(surnameCommaGivenname,folders , ResolveNameSearchLocation.ContactsOnly, true);
            var contactView = new ItemView(1);
            var filterCol   = new SearchFilter.SearchFilterCollection();

            if (!String.IsNullOrEmpty(achternaam))
            {
                var filterSurname = new SearchFilter.IsEqualTo(ContactSchema.Surname, achternaam);
                filterCol.Add(filterSurname);
            }
            if (!String.IsNullOrEmpty(voornaam))
            {
                var filterGivenName = new SearchFilter.IsEqualTo(ContactSchema.GivenName, voornaam);
                filterCol.Add(filterGivenName);
            }
            if (!String.IsNullOrEmpty(tussenvoegsel))
            {
                var filterTussenvoegsel = new SearchFilter.IsEqualTo(ContactSchema.MiddleName, tussenvoegsel);
                filterCol.Add(filterTussenvoegsel);
            }
            var contacts = service.FindItems(f_id, filterCol, contactView);

            if (contacts != null && contacts.Count() > 0 && contacts.First() != null)
            {
                Console.WriteLine("Contact Found");
                returnID = (contacts.First() as Contact).Id;
            }

            return(returnID);
        }
        public static List <IEmailMessage> GetIncomingEmails(
            string address,
            bool loadHtmlBody = false,
            CancellationToken cancellationToken = default)
        {
            Contract.Requires(!String.IsNullOrEmpty(address));

            var settings = GetConnectionSettings(address);

            List <IEmailMessage> GetEmails()
            {
                var service = new EWS.ExchangeService(settings.Version)
                {
                    Url = new Uri(settings.Url)
                };

                if (settings.UseDefaultCredentials)
                {
                    service.UseDefaultCredentials = true;
                }
                else
                {
                    service.Credentials = new NetworkCredential(settings.UserName, settings.Password, settings.Domain);
                }
                var mailbox       = new EWS.Mailbox(address);
                var inboxFolderId = new EWS.FolderId(EWS.WellKnownFolderName.Inbox, mailbox);
                var propertySet   = new EWS.PropertySet(EWS.BasePropertySet.FirstClassProperties)
                {
                    RequestedBodyType = EWS.BodyType.Text
                };

                if (loadHtmlBody)
                {
                    propertySet.Add(new EWS.ExtendedPropertyDefinition(ExtendedProperty_HtmlBody, EWS.MapiPropertyType.Binary));
                }
                propertySet.Add(new EWS.ExtendedPropertyDefinition(ExtendedProperty_ConversationId, EWS.MapiPropertyType.Binary));
                var view = new EWS.ItemView(100)
                {
                    OrderBy     = { { EWS.ItemSchema.DateTimeReceived, EWS.SortDirection.Ascending } },
                    PropertySet = propertySet
                };

                var emails = (from item in service.FindItems(inboxFolderId, view)
                              let email = item as EWS.EmailMessage
                                          where email != null
                                          select email).ToList();

                if (emails.Count > 0)
                {
                    propertySet.Add(EWS.ItemSchema.MimeContent);
                    service.LoadPropertiesForItems(emails, propertySet);
                }
                return(emails.ConvertAll(email => {
                    if (email.ItemClass == "IPM.Note.SMIME")
                    {
                        using (var memoryStream = new MemoryStream(email.MimeContent.Content))
                        {
                            memoryStream.Position = 0L;
                            var pkcs7Mime = (ApplicationPkcs7Mime)MimeEntity.Load(memoryStream);
                            CryptographyContext.Register(typeof(WindowsSecureMimeContext));
                            pkcs7Mime.Verify(out var mimeEntity);
                            var multipart = (Multipart)mimeEntity;
                            var body = multipart.OfType <TextPart>().FirstOrDefault()?.Text;
                            var message = multipart.OfType <TnefPart>().FirstOrDefault()?.ConvertToMessage();
                            return new EmailMessage(
                                email,
                                body,
                                message?.Attachments
                                .OfType <MimePart>()
                                .Select(mp => {
                                memoryStream.SetLength(0L);
                                using (var contentStream = mp.Content.Open())
                                {
                                    contentStream.CopyTo(memoryStream);
                                }
                                return new FileAttachment(
                                    mp.FileName,
                                    memoryStream.ToArray());
                            })
                                .ToArray());
                        }
                    }
                    else
                    {
                        return (IEmailMessage) new EmailMessage(email);
                    }
                }));
            }

            var retries = 0;

            while (true)
            {
                try
                {
                    return(GetEmails());
                }
                catch when(retries < settings.Retries)
                {
                    //await Task.Delay(settings.RetryDelay, cancellationToken);
                    retries++;
                }
            }
        }