Exemple #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);
        }
Exemple #2
0
        public void SendReceive()
        {
            try
            {
                if (!OutlookSession.IsOutlookRun)
                {
                    OutlookGUIInit.StartOutlook(ProcessWindowStyle.Minimized);
                    if (!IsMainWndReady())
                    {
                        return;
                    }
                    OutlookGUIInit.ActivateGUI(_mainWnd);
                }
                _explorer = OutlookGUIInit.IsOutlookExplorerReady(cTimeOut);
                if (_explorer == null)
                {
                    StandartJobs.MessageBox(cErrorCOMInitialize, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                ProcessDeliverNow( );
                ReleaseCOM();
            }
            catch (COMException exception)
            {
                _tracer.TraceException(exception);
            }
            catch (FileNotFoundException exception)
            {
                _tracer.TraceException(exception);
            }
            catch (InvalidComObjectException exception)
            {
                _tracer.TraceException(exception);
            }
            catch (InvalidCastException exception)
            {
                _tracer.TraceException(exception);
            }
        }
Exemple #3
0
        static public bool StartAndInitializeOutlook(  )
        {
            if (OutlookSession.IsOutlookRun)
            {
                return(true);
            }

            _com_OutlookExporer explorer = null;

            try
            {
                OutlookGUIInit.StartOutlook(ProcessWindowStyle.Minimized);
                IntPtr mainWnd = OutlookGUIInit.PrepareMainWndReady(2000);
                if ((int)mainWnd == 0)
                {
                    return(false);
                }
                ActivateGUI(mainWnd);
                return(IsOutlookExplorerReady(2000) != null);
            }
            catch (COMException exception)
            {
                Tracer._TraceException(exception);
                return(false);
            }
            finally
            {
                if (explorer != null)
                {
                    try
                    {
                        explorer.Release();
                    }
                    catch (COMException exception)
                    {
                        Tracer._TraceException(exception);
                    }
                }
            }
        }
Exemple #4
0
            private _com_OutlookMailItem GetItemFromID(string EntryID, string StoreID)
            {
                OutlookGUIInit.StartAndInitializeOutlook();
                _com_Outlook_Application outlook = null;
                _com_OutlookNameSpace    session = null;

                try
                {
                    outlook = new _com_Outlook_Application();
                    session = outlook.NameSpace;
                    return(session.GetItemFromID(EntryID, StoreID));
                }
                catch (Exception exception)
                {
                    ReportProblem(exception);
                }
                finally
                {
                    COM_Object.ReleaseIfNotNull(session);
                    COM_Object.ReleaseIfNotNull(outlook);
                }
                return(null);
            }
Exemple #5
0
        private bool CreateNewMessage(string subject, string body, EmailBodyFormat bodyFormat, ArrayList recipients,
                                      string[] attachments, bool useTemplatesInBody, ArrayList categories)
        {
            Settings.LoadSettings();
            OutlookGUIInit.StartAndInitializeOutlook();
            _com_Outlook_Application outlook = null;
            _com_OutlookMailItem     newMail = null;

            try
            {
                outlook         = new _com_Outlook_Application();
                newMail         = outlook.CreateNew();
                newMail.Subject = subject;

                bool validBody = !String.IsNullOrEmpty(body);

                if (useTemplatesInBody && Settings.UseSignature)
                {
                    body += "\r\n";
                    body += Settings.Signature;
                }

                if (validBody && EmailBodyFormat.Html == bodyFormat)
                {
                    try
                    {
                        newMail.BodyFormat = OlBodyFormat.olFormatHTML;
                    }
                    catch (Exception) {}
                    newMail.HTMLBody = body;
                }
                else
                if (validBody)
                {
                    try
                    {
                        newMail.BodyFormat = OlBodyFormat.olFormatPlain;
                    }
                    catch (Exception) {}
                    newMail.Body = body;
                }
                else
                if (!String.IsNullOrEmpty(body))
                {
                    newMail.Body = body;
                }

                if (recipients != null && recipients.Count > 0)
                {
                    OutlookSession.EMAPISession.AddRecipients(newMail.MAPIOBJECT, recipients);
                    if (Settings.SetCategoryFromContactWhenEmailSent && categories != null)
                    {
                        newMail.AddCategories(categories);
                    }
                }
                if (attachments != null && attachments.Length > 0)
                {
                    newMail.AddAttachments(attachments);
                }
                newMail.Display(false);
                return(true);
            }
            catch (Exception exception)
            {
                ReportProblem(exception);
            }
            finally
            {
                COM_Object.ReleaseIfNotNull(newMail);
                COM_Object.ReleaseIfNotNull(outlook);
            }
            return(false);
        }
Exemple #6
0
 private bool IsMainWndReady( )
 {
     _mainWnd = OutlookGUIInit.PrepareMainWndReady(cTimeOut);
     return((int)_mainWnd != 0);
 }