Exemple #1
0
        static void EnumerateStores(Outlook.Stores stores)
        {
            foreach (Store S in stores)
            {
                Debug.WriteLine(String.Format(@"{0}",
                                              S.FilePath));

                Outlook.Folder f = S.GetRootFolder() as Outlook.Folder;
                EnumerateFolder(f, 0);
            }
        }
 private static Outlook.Store GetStore(Outlook.Application app, string pstPath)
 {
     Outlook.Stores stores = app.Session.Stores;
     foreach (Outlook.Store store in stores)
     {
         if (store.FilePath == pstPath)
         {
             return(store);
         }
     }
     return(null);
 }
Exemple #3
0
        private static void Verificar_Correos(string directory_name, DateTime fec)
        {
            bool verfal;

            verfal = Existe_Buzon();
            if ((verfal == true))
            {
                ns     = ok.Session;
                stores = ns.Stores;
                // cnt debe empezar desde 1 (indice 0 no existe).
                int cnt = 1;
                foreach (Outlook.Store store in ns.Stores)
                {
                    // Si se quiere buscar otro buzon, se debe cambiar el valor en App.Config
                    if (store.DisplayName.ToLower().Contains(ConfigurationManager.AppSettings.Get("busqueda_buzon").ToLower().ToString()))
                    {
                        //MessageBox.Show(store.DisplayName.ToString());
                        break;
                    }
                    else
                    {
                        // Hasta que no entre en el if cnt se incremente (cnt representa las carpetas del buzon por indices).
                        cnt++;
                        // MsgBox(store.DisplayName.ToString)
                    }
                }

                // stores(cnt) es el buz�n el cual se buscar�n los correos a descargar.
                store         = stores[cnt];
                mailboxFolder = store.GetRootFolder();
                folders       = mailboxFolder.Folders;
                for (int j = 1; (j <= folders.Count); j++)
                {
                    folder = folders[j];
                    // folderList += folder.Name + Environment.NewLine
                    if ((folder.Name.ToLower().Equals(directory_name.ToLower())))
                    {
                        // MsgBox(folder.Name, , "Carpeta de Busqueda")
                        SeleccionarCarpeta(folder, fec);
                        j = folders.Count;
                    }
                }

                // MessageBox.Show(folderList, "Lista Outlook")
                //folderList = null;
                Marshal.ReleaseComObject(folder);
            }
        }
        public void List_Of_Folders()
        {
            Outlook.NameSpace  ns         = null;
            Outlook.Stores     stores     = null;
            Outlook.Store      store      = null;
            Outlook.MAPIFolder rootFolder = null;
            Outlook.Folders    folders    = null;
            Outlook.MAPIFolder folder     = null;
            string             folderList = string.Empty;

            try
            {
                Outlook.Application oApp = new Outlook.Application();
                ns         = oApp.Session;
                stores     = ns.Stores;
                store      = stores[1];
                rootFolder = store.GetRootFolder();
                folders    = rootFolder.Folders;

                for (int i = 1; i < folders.Count; i++)
                {
                    folder      = folders[i];
                    folderList += folder.Name + Environment.NewLine;
                    //if (folder != null)
                    //   // Marshal.ReleaseComObject(folder);
                }
                MessageBox.Show(folderList);
            }
            //finally
            //{
            //    if (folders != null)
            //        Marshal.ReleaseComObject(folders);
            //    if (folders != null)
            //        Marshal.ReleaseComObject(folders);
            //    if (rootFolder != null)
            //        Marshal.ReleaseComObject(rootFolder);
            //    if (store != null)
            //        Marshal.ReleaseComObject(store);
            //    if (stores != null)
            //        Marshal.ReleaseComObject(stores);
            //    if (ns != null)
            //        Marshal.ReleaseComObject(ns);
            //}
            catch (Exception ex)
            {
            }
        }
 //http://msdn.microsoft.com/en-us/library/office/ff184648.aspx
 public void EnumerateStores()
 {
     try {
         Outlook.Stores stores = Application.Session.Stores;
         foreach (Outlook.Store store in stores)
         {
             Outlook.Folder root =
                 store.GetRootFolder() as Outlook.Folder;
             EnumerateFolders(root);
         }
         MessageBox.Show("mails exported!");
     }
     catch (Exception ex)
     {
         MessageBox.Show("Exception:" + ex.Message + "\n[" + ex.StackTrace + "]");
     }
 }
Exemple #6
0
        internal static Dictionary <string, string> GetStoreIdsAndNames()
        {
            if (oOutlook == null)
            {
                return(null);                  // || ConnectionMode == Outlook.OlExchangeConnectionMode.olNoExchange) return null;
            }
            Dictionary <string, string> storeIdsAndNames = new Dictionary <string, string>();

            Outlook.Stores stores = oOutlook.Session.Stores;
            foreach (Outlook.Store store in stores)
            {
                if (!storeIdsAndNames.ContainsKey(store.StoreID))
                {
                    storeIdsAndNames.Add(store.StoreID, store.DisplayName);
                }
            }

            return(storeIdsAndNames);
        }
Exemple #7
0
        public Stores()
        {
            Outlook.Stores stores = null;
            Outlook.Store  store;
            string         storeList = string.Empty;

            try
            {
                stores = Globals.ThisAddIn.Application.Session.Stores;

                for (int i = 1; i <= stores.Count; i++)
                {
                    store = stores[i];

                    //Op.LogMessage("Store : " + store.DisplayName);
                    //Op.LogMessage("ExchangeStoreType : " + store.ExchangeStoreType.ToString());
                    //Op.LogMessage("FilePath : " + store.FilePath);
                    //Op.LogMessage("StoreID : " + store.StoreID);
                    //Op.LogMessage("IsDataFileStore : " + store.IsDataFileStore.ToString());

                    ITStore nextStore = new ITStore
                    {
                        DisplayName = store.DisplayName,
                        RootFolder  = store.GetRootFolder(),
                        StoreID     = store.StoreID
                    };
                    storesLookup.Add(store.DisplayName, nextStore);

                    if (store is object)
                    {
                        Marshal.ReleaseComObject(store);
                    }
                }
                Log.Message(storeList);
            }
            finally
            {
                if (stores is object)
                {
                    Marshal.ReleaseComObject(stores);
                }
            }
        }
Exemple #8
0
        private void ShowDisplayCountMails()

        {
            Outlook.Application objOutlook   = new Outlook.Application();
            Outlook.Explorer    _actExplorer = objOutlook.Application.ActiveExplorer();

            Outlook.Stores stores = objOutlook.Application.Session.Stores;

            if (_actExplorer == null)
            {
                ToolStripStatusLabel1.Text = "OutLook not running!";
                return;
            }

            dataGridViewInfo.Rows.Clear();

            dataGridViewInfo.Visible = true;
            comboBoxStore.Items.Clear();



            foreach (Outlook.Store store in stores)

            {
                string             NameStores      = store.DisplayName;
                int                _colItemsAlls   = 0;
                int                _colItemsUnread = 0;
                Outlook.MAPIFolder inbox           = store.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
                Outlook.Items      inBoxItems      = inbox.Items; //Outlook.MAPIFolder inBox
                _colItemsAlls = inBoxItems.Count;

                inBoxItems      = inBoxItems.Restrict(" [Unread] = true");
                _colItemsUnread = inBoxItems.Count;

                dataGridViewInfo.Rows.Add(NameStores, _colItemsAlls, _colItemsUnread);
                comboBoxStore.Items.Add(NameStores);
            }
        }
        private void LoadRules()
        {
            try
            {
                Application.ItemContextMenuDisplay += new Outlook.ApplicationEvents_11_ItemContextMenuDisplayEventHandler(Application_ItemContextMenuDisplay);
                Application.ContextMenuClose       += new Outlook.ApplicationEvents_11_ContextMenuCloseEventHandler(Application_ContextMenuClose);

                AllStores = Application.Session.Stores;
                foreach (Outlook.Store OS in AllStores)
                {
                    try
                    {
                        foreach (Outlook.Rule OR in OS.GetRules())
                        {
                            try
                            {
                                Debug.WriteLine(OR.Name);
                                RulesList.Add(OR);
                            }
                            catch (Exception ex)
                            {
                                Debug.WriteLine(ex.Message);
                            }
                        }
                    }
                    catch
                    {
                        // error loading store
                    }
                }
            }
            catch (Exception ex)
            {
                //      MessageBox.Show(ex.Message);
            }
        }
Exemple #10
0
 /// <summary>
 /// Gets the list of outlook stores for further display
 /// </summary>
 /// <param name="stores"></param>
 internal void setStores(Microsoft.Office.Interop.Outlook.Stores stores)
 {
     this.stores = stores;
 }
Exemple #11
0
        private void StartRun()
        {
            string _Subject  = GetSubject();
            string _strPath  = GetAttachpath();
            string _strPromt = "Обробка закінчена";

            Outlook.Application objOutlook   = new Outlook.Application();
            Outlook.Explorer    _actExplorer = objOutlook.Application.ActiveExplorer();

            Outlook.Stores stores = objOutlook.Application.Session.Stores;

            if (_actExplorer == null)
            {
                ToolStripStatusLabel1.Text = "OutLook not running!";
                return;
            }



            Outlook.Store storework = null;
            for (int i = 1; i <= stores.Count; i++)
            {
                if (stores[i].DisplayName == GetStore())
                {
                    storework = stores[i];
                    break;
                }
            }


            if (storework == null)
            {
                ToolStripStatusLabel1.Text = "OutLook store:" + GetStore() + "not found!";
                return;
            }


            Outlook.MAPIFolder inBox         = storework.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
            Outlook.Items      inBoxItems    = inBox.Items; //Outlook.MAPIFolder inBox
            Outlook.MAPIFolder OutBoxSubject = null;

            foreach (Outlook.Folder folder in inBox.Folders)
            {
                if (folder.Name.Equals(_Subject))
                {
                    OutBoxSubject = folder;
                }
            }

            if (OutBoxSubject == null)
            {
                OutBoxSubject = inBox.Folders.Add(_Subject);
            }


            ToolStripStatusLabel1.Text = "Вхідних : " + inBoxItems.Count;
            //inBoxItems = inBoxItems.Restrict( " [Unread] = true");
            inBoxItems = inBoxItems.Restrict("[Subject] = " + _Subject + "");

            ToolStripStatusLabel2.Visible    = true;
            ToolStripStatusLabel3.Visible    = true;
            ToolStripProgressBarMain.Visible = true;
            ToolStripProgressBarMain.Maximum = inBoxItems.Count;
            ToolStripProgressBarMain.Value   = 0;

            try
            {
                // BASIC CICLE

                SetRunStage(true);

                int _allattachment = 0, _allmail = 1;

                for (int i = inBoxItems.Count; i > 0; i--)

                {
                    Application.DoEvents();
                    Outlook.MailItem workLetter = inBoxItems[i] as Outlook.MailItem;

                    ToolStripStatusLabel3.Text = "Обробка листа: " + _allmail++;
                    ToolStripProgressBarMain.Value++;
                    Application.DoEvents();


                    if (!GetRunStage())
                    {
                        _strPromt = "Обробка перервана";

                        break;
                    }

                    Application.DoEvents();

                    if (workLetter.Subject == _Subject)

                    {
                        if (workLetter.Attachments.Count > 0)
                        {
                            string _folder = "";

                            _allattachment++;

                            for (int j = 1; j <= workLetter.Attachments.Count; j++)
                            {
                                _folder = MakeFolderForAttacment(workLetter.Attachments[j].FileName);
                                if (!Directory.Exists(_folder))
                                {
                                    Directory.CreateDirectory(_folder);
                                }
                                workLetter.Attachments[j].SaveAsFile(Path.Combine(_folder + "\\" + workLetter.Attachments[j].FileName));
                                ToolStripStatusLabel2.Text = "Оброблено вкладень: " + _allattachment;
                            }
                            workLetter.Move(OutBoxSubject);
                        }

                        else
                        {
                            workLetter.Delete();
                        }
                    }
                }
            }// end try


            catch (Exception ex)
            {
                string errorInfo = (string)ex.Message
                                   .Substring(0, 11);
                if (errorInfo == "Cannot save")
                {
                    MessageBox.Show(@"Bad folder to a save attacment");
                }
                MessageBox.Show(ex.Message);
                _strPromt = "OutLook was lost!";
            }

            // finally
            {
                EndRun(_strPromt);
                inBoxItems = null;
                objOutlook = null;
            }
        }
        private void LoadRules()
        {
            try
            {
                Application.ItemContextMenuDisplay += new Outlook.ApplicationEvents_11_ItemContextMenuDisplayEventHandler(Application_ItemContextMenuDisplay);
                Application.ContextMenuClose += new Outlook.ApplicationEvents_11_ContextMenuCloseEventHandler(Application_ContextMenuClose);

                AllStores = Application.Session.Stores;
                foreach (Outlook.Store OS in AllStores)
                {
                    try
                    {
                        foreach (Outlook.Rule OR in OS.GetRules())
                        {
                            try
                            {
                                Debug.WriteLine(OR.Name);
                                RulesList.Add(OR);
                            }
                            catch (Exception ex)
                            {
                                Debug.WriteLine(ex.Message);
                            }
                        }
                    }
                    catch
                    {
                        // error loading store
                    }
                }
            }
            catch (Exception ex)
            {
                //      MessageBox.Show(ex.Message);
            }
        }