Exemplo n.º 1
0
        static public _com_OutlookExporer IsOutlookExplorerLoaded( )
        {
            Outlook.Application outlook   = null;
            Outlook.NameSpace   nameSpace = null;
            _com_OutlookExporer explorer  = null;

            _isFileNotFoundHappened = false;
            try
            {
                _tracer.Trace("Looking for explorer");
                OutlookGUIInit.DebugMessageBox("Looking for explorer");

                outlook = new Outlook.ApplicationClass();
                _tracer.Trace("Outlook.Application object has been initialized properly.");

                nameSpace = outlook.GetNamespace("MAPI");
                _tracer.Trace("Outlook.NameSpace object has been initialized properly? - " + (nameSpace != null).ToString());

                explorer = new _com_OutlookExporer(outlook.ActiveExplorer());
                _tracer.Trace("_com_OutlookExporer wrapper object has been initialized properly.");
                OutlookGUIInit.DebugMessageBox("Get ActiveExplorer");

                if (explorer == null)
                {
                    _tracer.Trace("Outlook explorer is not found");
                }
                else
                {
                    _tracer.Trace("Outlook explorer is found");
                }
            }
            catch (FileNotFoundException exception)
            {
                _isFileNotFoundHappened = true;
                _tracer.TraceException(exception);
            }
            catch (COMException exception)
            {
                _tracer.TraceException(exception);
            }
            catch (InvalidComObjectException exception)
            {
                _tracer.TraceException(exception);
            }
            catch (InvalidCastException exception)
            {
                _tracer.TraceException(exception);
            }
            finally
            {
                COM_Object.Release(outlook);
                COM_Object.Release(nameSpace);
            }
            return(explorer);
        }
        public ArrayList GetMail()
        {
            MailMessage message;

            Outlook.MailItem msgInbox;
            ArrayList        arrayMessages = null;

            Outlook.ApplicationClass appOutlook = null;

            try
            {
                arrayMessages = new ArrayList();

                //connect to the CDO library
                appOutlook = new Outlook.ApplicationClass();
                Outlook.NameSpace appNamespace = appOutlook.GetNamespace("MAPI");
                appNamespace.Logon("jkanalakis", "jkanalakis", false, false);

                //navigate to the inbox folder
                Outlook.Explorer exp = appOutlook.Explorers.Item(1);

                for (int intIdx = 1; intIdx <= exp.CurrentFolder.Items.Count; intIdx++)
                {
                    //retrieve the next message from the inbox
                    msgInbox = (Outlook.MailItem)exp.CurrentFolder.Items.Item(intIdx);

                    //convert data into MailMessage
                    message         = new MailMessage();
                    message.Subject = msgInbox.Subject;
                    message.Body    = msgInbox.Body;

                    //add MailMessage to the ArrayList
                    arrayMessages.Add(message);
                }
            }
            catch (Exception exception)
            {
                LogEvent(exception.Message);
            }
            finally
            {
                Marshal.ReleaseComObject(appOutlook);
            }

            return(arrayMessages);
        }