Esempio n. 1
0
        public TestResult DoTest()
        {
            Outlook.Application application = null;
            DateTime            startTime   = DateTime.Now;

            try
            {
                // start outlook
                application = new Outlook.Application(true);
                NetOffice.OutlookSecurity.Suppress.Enabled = true;

                // Get inbox
                Outlook._NameSpace outlookNS   = application.GetNamespace("MAPI");
                Outlook.MAPIFolder inboxFolder = outlookNS.GetDefaultFolder(OlDefaultFolders.olFolderInbox);

                Outlook._Items items = inboxFolder.Items;
                COMObject      item  = null;
                int            i     = 1;
                do
                {
                    if (null == item)
                    {
                        item = items.GetFirst() as COMObject;
                    }

                    // not every item is a mail item
                    Outlook.MailItem mailItem = item as Outlook.MailItem;
                    if (null != mailItem)
                    {
                        Console.WriteLine(mailItem.SenderName);
                    }

                    if (null != item)
                    {
                        item.Dispose();
                    }

                    item = items.GetNext() as COMObject;
                    i++;
                } while (null != item);

                return(new TestResult(true, DateTime.Now.Subtract(startTime), "", null, string.Format("{0} Inbox Items.", items.Count)));
            }
            catch (Exception exception)
            {
                return(new TestResult(false, DateTime.Now.Subtract(startTime), exception.Message, exception, ""));
            }
            finally
            {
                if (null != application)
                {
                    if (!application.FromProxyService)
                    {
                        application.Quit();
                    }
                    application.Dispose();
                }
            }
        }
Esempio n. 2
0
        private void ListInBoxFolder(Outlook.MAPIFolder inboxFolder)
        {
            // setup ui
            listView1.Items.Clear();

            // we fetch the inbox folder items
            Outlook._Items items = inboxFolder.Items;
            ICOMObject     item  = null;
            int            i     = 1;

            do
            {
                if (null == item)
                {
                    item = items.GetFirst() as ICOMObject;
                    if (null == item)
                    {
                        break;
                    }
                }

                // not every item is a mail item
                Outlook.MailItem mailItem = item as Outlook.MailItem;
                if (null != mailItem)
                {
                    ListViewItem newItem = listView1.Items.Add(mailItem.SenderName);
                    newItem.SubItems.Add(mailItem.Subject);
                }

                item.Dispose();
                item = items.GetNext() as ICOMObject;
                i++;
            } while (null != item);

            // dipsose items and childs
            items.Dispose();
        }