Exemplo n.º 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            Outlook.Application application = COMObject.CreateByRunningInstance <Outlook.Application>();

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

            for (int i = 1; i <= 100; i++)
            {
                labelCurrentCount.Text = "Step " + i.ToString();
                Application.DoEvents();
                if (_cancel)
                {
                    break;
                }

                // fetch inbox
                ListInBoxFolder(inboxFolder);
            }

            labelCurrentCount.Text = "Done!";

            // close outlook and dispose
            if (application.FromProxyService)
            {
                application.Quit();
            }
            application.Dispose();
        }
Exemplo n.º 2
0
 public override void Run()
 {
     try
     {
         if (!(this.Owner is LeadDetailController))
         {
             return;
         }
         LeadDetailController leadPresenter = (LeadDetailController)this.Owner;
         LateBindingApi.Core.Factory.Initialize();
         Outlook.Application outlookApplication = new Outlook.Application();
         Outlook.MailItem    KatrinEmal         = outlookApplication.CreateItem(OlItemType.olMailItem) as Outlook.MailItem;
         object emailToObject = leadPresenter.ObjectEntity.GetType().GetProperty("EmailAddress").GetValue(leadPresenter.ObjectEntity, null);
         string emailTo       = emailToObject == null ? string.Empty : emailToObject.ToString();
         if (!string.IsNullOrEmpty(emailTo))
         {
             KatrinEmal.Recipients.Add(emailTo);
         }
         KatrinEmal.Importance = OlImportance.olImportanceNormal;
         KatrinEmal.Display();
     }
     catch (Exception ex)
     {
         MessageService.ShowException(ex, ResourceService.GetString("EmailExceptionTip"));
     }
 }
Exemplo n.º 3
0
        private void buttonStartExample_Click(object sender, EventArgs e)
        {
            // start outlook by trying to access running application first
            Outlook.Application outlookApplication = COMObject.CreateByRunningInstance <Outlook.Application>();

            // enum contacts
            int i = 0;

            Outlook.MAPIFolder contactFolder = outlookApplication.Session.GetDefaultFolder(OlDefaultFolders.olFolderContacts);
            foreach (ICOMObject item in contactFolder.Items)
            {
                Outlook.ContactItem contact = item as Outlook.ContactItem;
                if (null != contact)
                {
                    i++;
                    ListViewItem listItem = listViewContacts.Items.Add(i.ToString());
                    listItem.SubItems.Add(contact.CompanyAndFullName);
                }
            }

            // close outlook and dispose
            if (!outlookApplication.FromProxyService)
            {
                outlookApplication.Quit();
            }
            outlookApplication.Dispose();
        }
Exemplo n.º 4
0
        public TestResult DoTest()
        {
            Outlook.Application application = null;
            DateTime startTime = DateTime.Now;
            try
            {
                // start outlook
                application = new Outlook.Application();
                NetOffice.OutlookSecurity.Supress.Enabled = true;

                // Create a new MailItem.
                Outlook.MailItem mailItem = application.CreateItem(OlItemType.olMailItem) as Outlook.MailItem;

                // prepare item and send
                mailItem.Recipients.Add("*****@*****.**");
                mailItem.Subject = "NetOffice Test Mail";
                mailItem.Body = "This is a NetOffice test mail from the MainTests.(C#)";
                mailItem.Send();

                return new TestResult(true, DateTime.Now.Subtract(startTime), "", null, "");
            }
            catch (Exception exception)
            {
                return new TestResult(false, DateTime.Now.Subtract(startTime), exception.Message, exception, "");
            }
            finally
            {
                if (null != application)
                {
                    application.Quit();
                    application.Dispose();
                }
                NetOffice.OutlookSecurity.Supress.Enabled = false;
            }
        }
Exemplo n.º 5
0
        public TestResult DoTest()
        {
            Outlook.Application application = null;
            DateTime startTime = DateTime.Now;
            try
            {
                // start outlook
                application = new Outlook.Application();
                NetOffice.OutlookSecurity.Supress.Enabled = true;

                Outlook.TaskItem newTask = application.CreateItem(OlItemType.olTaskItem) as Outlook.TaskItem;
                newTask.Subject = "Test item";
                newTask.Body = "hello";
                newTask.DueDate = DateTime.Now;
                newTask.Importance = OlImportance.olImportanceHigh;
                newTask.Close(OlInspectorClose.olDiscard);

                return new TestResult(true, DateTime.Now.Subtract(startTime), "", null, "");
            }
            catch (Exception exception)
            {
                return new TestResult(false, DateTime.Now.Subtract(startTime), exception.Message, exception, "");
            }
            finally
            {
                if (null != application)
                {
                    application.Quit();
                    application.Dispose();
                }
                NetOffice.OutlookSecurity.Supress.Enabled = false;
            }
        }
Exemplo n.º 6
0
        public ResultDTO SendEmail(IEnumerable <EmailRecipientDTO> recipientDtos, string subject, string body)
        {
            var result = new ResultDTO
            {
                Errors = new List <ErrorDTO>()
            };

            try
            {
                var outlookApplication = new Outlook.Application();
                var mailItem           = BuildMail(recipientDtos, subject, body, outlookApplication);
                mailItem.Send();
            }
            catch (ArgumentException ex)
            {
                var error = new ErrorDTO
                {
                    FullException = ex,
                    Message       = "Configuration error "
                };
                result.Errors.Add(error);
            }

            return(result);
        }
Exemplo n.º 7
0
        public void RunExample()
        {
            // start outlook by trying to access running application first
            // if its failed to resolve a running instance, we create a new one here
            Outlook.Application outlookApplication = COMObject.CreateByRunningInstance <Outlook.Application>();

            // create a new TaskItem.
            Outlook.TaskItem newTask = outlookApplication.CreateItem(OlItemType.olTaskItem) as Outlook.TaskItem;

            // Configure the task at hand and save it.
            newTask.Subject    = "Don't forget to check for NoScript updates";
            newTask.Body       = "check updates here: https://addons.mozilla.org/de/firefox/addon/noscript";
            newTask.DueDate    = DateTime.Now;
            newTask.Importance = OlImportance.olImportanceHigh;
            newTask.Save();

            // close outlook and dispose
            if (!outlookApplication.FromProxyService)
            {
                outlookApplication.Quit();
            }
            outlookApplication.Dispose();

            HostApplication.ShowFinishDialog("Done!", null);
        }
Exemplo n.º 8
0
        public TestResult DoTest()
        {
            Outlook.Application application = null;
            DateTime startTime = DateTime.Now;
            try
            {
                // start outlook
                application = new Outlook.Application();
                NetOffice.OutlookSecurity.Supress.Enabled = true;

                // enum contacts 
                Outlook.MAPIFolder contactFolder = application.Session.GetDefaultFolder(OlDefaultFolders.olFolderContacts);
                for (int i = 1; i <= contactFolder.Items.Count; i++)
                {
                    Outlook.ContactItem contact = contactFolder.Items[i] as Outlook.ContactItem;
                    if (null != contact)
                        Console.WriteLine(contact.CompanyAndFullName);
                }

                return new TestResult(true, DateTime.Now.Subtract(startTime), "", null, string.Format("{0} ContactFolder Items.", contactFolder.Items.Count));
            }
            catch (Exception exception)
            {
                return new TestResult(false, DateTime.Now.Subtract(startTime), exception.Message, exception, "");
            }
            finally
            {
                if (null != application)
                {
                    application.Quit();
                    application.Dispose();
                }
                NetOffice.OutlookSecurity.Supress.Enabled = false;
            }
        }
Exemplo n.º 9
0
        public void RunExample()
        {
            // start outlook by trying to access running application first
            Outlook.Application outlookApplication = new Outlook.Application(true);

            // SendAndReceive is supported from Outlook 2007 or higher
            // we check at runtime the feature is available
            if (outlookApplication.Session.EntityIsAvailable("SendAndReceive"))
            {
                // one simple call
                outlookApplication.Session.SendAndReceive(false);
            }
            else
            {
                HostApplication.ShowErrorDialog("This version of MS-Outlook doesnt support SendAndReceive.", null);
            }

            // close outlook and dispose
            if (!outlookApplication.FromProxyService)
            {
                outlookApplication.Quit();
            }
            outlookApplication.Dispose();

            HostApplication.ShowFinishDialog("Done!", null);
        }
Exemplo n.º 10
0
        private void button1_Click(object sender, EventArgs e)
        {
            Outlook.Application application = new Outlook.Application();

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

            for (int i = 1; i <= 100; i++)
            {
                labelCurrentCount.Text = "Step " + i.ToString();
                Application.DoEvents();
                if (_cancel)
                    break;

                // fetch inbox
                ListInBoxFolder(inboxFolder);
            }

            labelCurrentCount.Text = "Done!";

            // close outlook and dispose
            application.Quit();
            application.Dispose();
        }
Exemplo n.º 11
0
        private void buttonStartExample_Click(object sender, EventArgs e)
        {
            // start outlook
            Outlook.Application outlookApplication = new Outlook.Application();

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

            // setup gui
            listViewInboxFolder.Items.Clear();
            labelItemsCount.Text = string.Format("You have {0} e-mails.", inboxFolder.Items.Count);

            // we fetch the inbox folder items.
            foreach (COMObject item in inboxFolder.Items)
            {
                // not every item in the inbox is a mail item
                Outlook.MailItem mailItem = item as Outlook.MailItem;
                if (null != mailItem)
                {
                    ListViewItem newItem = listViewInboxFolder.Items.Add(mailItem.SenderName);
                    newItem.SubItems.Add(mailItem.Subject);
                }
            }

            // close outlook and dispose
            outlookApplication.Quit();
            outlookApplication.Dispose();
        }
Exemplo n.º 12
0
 /// <summary>
 /// Occurs when Outlook quits.
 /// </summary>
 private static void Outlook_Quit()
 {
     s_outlookApplication.QuitEvent -= Outlook_Quit;
     s_outlookApplication.Dispose();
     s_outlookApplication = null;
     s_mapiFolder = null;
 }
Exemplo n.º 13
0
        private void buttonStartExample_Click(object sender, EventArgs e)
        {
            // start outlook by trying to access running application first
            Outlook.Application outlookApplication = new Outlook.Application(true);

            // create MailItem and register close event
            Outlook.MailItem mailItem = outlookApplication.CreateItem(OlItemType.olMailItem) as Outlook.MailItem;
            mailItem.CloseEvent += new NetOffice.OutlookApi.MailItem_CloseEventHandler(mailItem_CloseEvent);

            // BodyFormat is not available in Outlook 2000, we check at runtime the property is available
            if (mailItem.EntityIsAvailable("BodyFormat"))
            {
                mailItem.BodyFormat = OlBodyFormat.olFormatPlain;
            }
            mailItem.Body    = "ExampleBody";
            mailItem.Subject = "ExampleSubject";
            mailItem.Display();
            mailItem.Close(OlInspectorClose.olDiscard);

            // close outlook and dispose
            if (!outlookApplication.FromProxyService)
            {
                outlookApplication.Quit();
            }
            outlookApplication.Dispose();
        }
Exemplo n.º 14
0
        private void buttonStartExample_Click(object sender, EventArgs e)
        {
            // start outlook
            Outlook.Application outlookApplication = new Outlook.Application();

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

            // setup gui
            listViewInboxFolder.Items.Clear();
            labelItemsCount.Text = string.Format("You have {0} e-mails.", inboxFolder.Items.Count);

            // we fetch the inbox folder items.
            foreach (COMObject item in inboxFolder.Items)
            {
                // not every item in the inbox is a mail item
                Outlook.MailItem mailItem = item as Outlook.MailItem;
                if (null != mailItem)
                {
                    ListViewItem newItem = listViewInboxFolder.Items.Add(mailItem.SenderName);
                    newItem.SubItems.Add(mailItem.Subject);
                }
            }

            // close outlook and dispose
            outlookApplication.Quit();
            outlookApplication.Dispose();
        }
Exemplo n.º 15
0
        public TestResult DoTest()
        {
            Outlook.Application application = null;
            DateTime            startTime   = DateTime.Now;

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

                Outlook.TaskItem newTask = application.CreateItem(OlItemType.olTaskItem) as Outlook.TaskItem;
                newTask.Subject    = "Test item";
                newTask.Body       = "hello";
                newTask.DueDate    = DateTime.Now;
                newTask.Importance = OlImportance.olImportanceHigh;
                newTask.Close(OlInspectorClose.olDiscard);

                return(new TestResult(true, DateTime.Now.Subtract(startTime), "", null, ""));
            }
            catch (Exception exception)
            {
                return(new TestResult(false, DateTime.Now.Subtract(startTime), exception.Message, exception, ""));
            }
            finally
            {
                if (null != application)
                {
                    application.Quit();
                    application.Dispose();
                }
            }
        }
Exemplo n.º 16
0
 static void Main(string[] args)
 {
     using (var suppress = new Automation())
     {
         Console.WriteLine("Concept Test - SuppressOutlookSecurity");
         suppress.Enabled   = true;
         suppress.OnAction += Suppress_OnAction;
         suppress.OnError  += Suppress_OnError;
         Outlook.Application application = null;
         try
         {
             application = new Outlook.ApplicationClass(new NetOffice.Core(), true);
             SendMail(application);
             Console.WriteLine("Press any key...");
             Console.ReadKey();
         }
         catch (Exception exception)
         {
             Console.WriteLine(exception.ToString());
         }
         finally
         {
             if (null != application)
             {
                 if (application.FromProxyService)
                 {
                     application.Quit();
                 }
                 application.Dispose();
             }
         }
     }
 }
Exemplo n.º 17
0
        public TestResult DoTest()
        {
            Outlook.Application application = null;
            DateTime            startTime   = DateTime.Now;

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

                // Create a new MailItem.
                Outlook.MailItem mailItem = application.CreateItem(OlItemType.olMailItem) as Outlook.MailItem;

                // prepare item and send
                mailItem.Recipients.Add("*****@*****.**");
                mailItem.Subject = "NetOffice Test Mail";
                mailItem.Body    = "This is a NetOffice test mail from the MainTests.(C#)";
                mailItem.Send();

                return(new TestResult(true, DateTime.Now.Subtract(startTime), "", null, ""));
            }
            catch (Exception exception)
            {
                return(new TestResult(false, DateTime.Now.Subtract(startTime), exception.Message, exception, ""));
            }
            finally
            {
                if (null != application)
                {
                    application.Quit();
                    application.Dispose();
                }
            }
        }
Exemplo n.º 18
0
 static void Main(string[] args)
 {
     Console.WriteLine("Concept Test - SuppressOutlookSecurity");
     Suppress.Enabled   = true;
     Suppress.OnAction += new Suppress.SecurityDialogAction(Suppress_OnAction);
     Suppress.OnError  += new Suppress.ErrorOccuredEventHandler(Suppress_OnError);
     Outlook.Application application = null;
     try
     {
         application = new Outlook.Application();
         SendMail(application);
         Console.WriteLine("Press any key...");
         Console.ReadKey();
     }
     catch (Exception exception)
     {
         Console.WriteLine(exception.ToString());
     }
     finally
     {
         if (null != application)
         {
             application.Quit();
             application.Dispose();
         }
     }
 }
Exemplo n.º 19
0
        public TestResult DoTest()
        {
            Outlook.Application application = null;
            DateTime startTime = DateTime.Now;
            try
            {
                // start outlook
                application = new Outlook.Application();
                NetOffice.OutlookSecurity.Supress.Enabled = true;

                if (application.Session.EntityIsAvailable("SendAndReceive"))
                    application.Session.SendAndReceive(false);
                else
                    return new TestResult(false, DateTime.Now.Subtract(startTime), "SendAndReceive is not supported from this Outlook Version.", null, "");

                return new TestResult(true, DateTime.Now.Subtract(startTime), "", null, "");
            }
            catch (Exception exception)
            {
                return new TestResult(false, DateTime.Now.Subtract(startTime), exception.Message, exception, "");
            }
            finally
            {
                if (null != application)
                {
                    application.Quit();
                    application.Dispose();
                }
                NetOffice.OutlookSecurity.Supress.Enabled = false;
            }
        }
Exemplo n.º 20
0
        public TestResult DoTest()
        {
            Outlook.Application application = null;
            DateTime startTime = DateTime.Now;
            try
            {
                // start outlook
                application = new Outlook.Application();
                NetOffice.OutlookSecurity.Suppress.Enabled = true;

                if (application.Session.EntityIsAvailable("SendAndReceive"))
                {
                    application.Session.SendAndReceive(false);
                    // give few seconds to outlook or may its failed to quit because its busy - depending on how many mails comes in
                    System.Threading.Thread.Sleep(3000);
                }
                else
                    return new TestResult(false, DateTime.Now.Subtract(startTime), "SendAndReceive is not supported from this Outlook Version.", null, "");

                return new TestResult(true, DateTime.Now.Subtract(startTime), "", null, "");
            }
            catch (Exception exception)
            {
                return new TestResult(false, DateTime.Now.Subtract(startTime), exception.Message, exception, "");
            }
            finally
            {
                if (null != application)
                {
                    application.Quit();
                    application.Dispose();
                }
            }
        }
Exemplo n.º 21
0
 static void Main(string[] args)
 {
     Console.WriteLine("Concept Test - SuppressOutlookSecurity");
     Suppress.Enabled = true;
     Suppress.OnAction += new Suppress.SecurityDialogAction(Suppress_OnAction);
     Suppress.OnError += new Suppress.ErrorOccuredEventHandler(Suppress_OnError);
     Outlook.Application application = null;
     try
     {
         application = new Outlook.Application();
         SendMail(application);
         Console.WriteLine("Press any key...");
         Console.ReadKey();
     }
     catch (Exception exception)
     {
         Console.WriteLine(exception.ToString());
     }
     finally
     {
         if (null != application)
         {
             application.Quit();
             application.Dispose();
         }
     }
 }
 public override void Run()
 {
     try
     {
         ProjectWeekReportDetailController projectWeekReportController = (ProjectWeekReportDetailController)this.Owner;
         if (!(this.Owner is ProjectWeekReportDetailController))
         {
             return;
         }
         LateBindingApi.Core.Factory.Initialize();
         Outlook.Application outlookApplication = new Outlook.Application();
         Outlook.MailItem    KatrinEmal         = outlookApplication.CreateItem(OlItemType.olMailItem) as Outlook.MailItem;
         KatrinEmal.Subject = projectWeekReportController.ObjectName;
         string emailTo = "";
         KatrinEmal.Display();
         string sourceHtmlBody = KatrinEmal.HTMLBody;
         string emailBody      = InitEmailMessage(out emailTo);
         emailBody          += sourceHtmlBody;
         KatrinEmal.HTMLBody = emailBody;
         if (!string.IsNullOrEmpty(emailTo))
         {
             KatrinEmal.Recipients.Add(emailTo);
         }
         KatrinEmal.Importance = OlImportance.olImportanceNormal;
     }
     catch (Exception ex)
     {
         MessageService.ShowException(ex, ResourceService.GetString("EmailExceptionTip"));
     }
 }
Exemplo n.º 23
0
        private void buttonStartExample_Click(object sender, EventArgs e)
        {
            // start outlook by trying to access running application first
            Outlook.Application outlookApplication = new Outlook.Application(true);

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

            // setup ui
            listViewInboxFolder.Items.Clear();
            labelItemsCount.Text = string.Format("You have {0} e-mail(s).", inboxFolder.Items.Count);

            // we fetch the inbox folder items by a custom enumerator
            foreach (ICOMObject item in inboxFolder.Items)
            {
                // not every item in the inbox is a mail item
                Outlook.MailItem mailItem = item as Outlook.MailItem;
                if (null != mailItem)
                {
                    ListViewItem newItem = listViewInboxFolder.Items.Add(mailItem.SenderName);
                    newItem.SubItems.Add(mailItem.Subject);
                }
            }

            // close outlook and dispose
            if (!outlookApplication.FromProxyService)
            {
                outlookApplication.Quit();
            }
            outlookApplication.Dispose();
        }
Exemplo n.º 24
0
        public void OnGenerateDayReport(object sender, EventArgs e)
        {
            LateBindingApi.Core.Factory.Initialize();
            Outlook.Application outlookApplication = new Outlook.Application();

            DateTime    thisDay       = DateTime.Today;
            DateTime    nextDay       = thisDay.AddDays(1);
            IEnumerable taskList      = GetTasks(thisDay);
            var         projectIdList = taskList.AsQueryable().Select("ProjectId").Cast <Guid>().Distinct <Guid>();

            if (projectIdList.ToList().Count <= 0)
            {
                XtraMessageBox.Show(Properties.Resources.NoTaskTip,
                                    Properties.Resources.Katrin,
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Information,
                                    MessageBoxDefaultButton.Button1);
                return;
            }
            foreach (Guid projectId in projectIdList)
            {
                Outlook.MailItem KatrinEmal = outlookApplication.CreateItem(OlItemType.olMailItem) as Outlook.MailItem;
                KatrinEmal.Subject = "";
                string emailTo        = "";
                string sourceHtmlBody = KatrinEmal.HTMLBody;
                KatrinEmal.HTMLBody = InitEmailMessage(out emailTo, thisDay, nextDay, projectId, taskList);
                if (!string.IsNullOrEmpty(emailTo))
                {
                    KatrinEmal.Recipients.Add(emailTo);
                }
                KatrinEmal.Importance = OlImportance.olImportanceNormal;
                KatrinEmal.Display();
            }
        }
Exemplo n.º 25
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();
                }
            }
        }
Exemplo n.º 26
0
        public WeekParser(Outlook.Application outlookApp, string mailBody)
        {
            thisOutlookApp = outlookApp;
            EntireMailBody = mailBody;

            threadParser = new Thread(this.Start);
            threadParser.Start();
        }
Exemplo n.º 27
0
 private static void SendMail(Outlook.Application application)
 {
     Outlook.MailItem mailItem = application.CreateItem(OlItemType.olMailItem) as Outlook.MailItem;
     mailItem.Recipients.Add("*****@*****.**");
     mailItem.Subject = "Concept Test - SuppressOutlookSecurity";
     mailItem.Body    = "This is a test mail from NetOffice concept test.";
     mailItem.Send();
 }
Exemplo n.º 28
0
 private void btnStop_Click(object sender, EventArgs e)
 {
     if (m_app != null)
     {
         m_app.Dispose();
     }
     m_app = null;
 }
Exemplo n.º 29
0
    public static void Main(string[] args)
    {
        try
        {
            if (args.Length == 1)
            {
                // Create an Outlook application.
                Outlook._Application oApp;
                oApp = new Outlook.Application();

                // Create a new MailItem.
                Outlook._MailItem oMsg;
                oMsg = (Outlook._MailItem)oApp.CreateItem((OlItemType)NetOffice.OutlookApi.Enums.OlItemType.olMailItem);

                // set the subject to the PDF file name without the path + attached
                oMsg.Subject = Path.GetFileName(args[0]) + " attached";

                // customize these fields to add "To" address or body
                // oMsg.To =
                // oMsg.Body =

                // Add the PDF as an attachment
                string sSource      = args[0];
                string sDisplayName = Path.GetFileName(args[0]);
                string sBodyLen     = "0";

                Outlook.Attachments oAttachs = oMsg.Attachments;
                Outlook.Attachment  oAttach;
                oAttach = oAttachs.Add(sSource, OlAttachmentType.olByValue, Convert.ToInt32(sBodyLen) + 1, sDisplayName);

                // Display
                oMsg.Display(true);

                // Send
                // oMsg.Send()

                // close OutlookApi And dispose
                oApp.Quit();
                oApp.Dispose();

                // Clean up
                oApp     = null /* TODO Change to default(_) if this is not a reference type */;
                oMsg     = null /* TODO Change to default(_) if this is not a reference type */;
                oAttach  = null /* TODO Change to default(_) if this is not a reference type */;
                oAttachs = null /* TODO Change to default(_) if this is not a reference type */;
            }
        }
        catch (Exception ex)
        {
            var exception_description = string.Format("Win2PDF Send To Outlook plug-in exception {0}, stack {1}, targetsite {2}", ex.Message, ex.StackTrace, ex.TargetSite);
            System.Windows.Forms.MessageBox.Show(exception_description);
            using (EventLog eventLog = new EventLog("Application"))
            {
                eventLog.Source = "Win2PDF";
                eventLog.WriteEntry(exception_description, EventLogEntryType.Error, 101);
            }
        }
    }
Exemplo n.º 30
0
        public Outlok()
        {
            NetOffice.OutlookApi.Application outlookApplication = new Outlook.Application();
            outlookApplication.NewMailExEvent += new Outlook.Application_NewMailExEventHandler(outlook_newmail);
            outlookNS = outlookApplication.Session;

            inboxFolder = outlookNS.Folders["*****@*****.**"].Folders["Inbox"];
            einbuchung  = outlookNS.Folders["*****@*****.**"].Folders["[Gmail]"].Folders["DevDB"].Folders["Einbuchung"];
            ausbuchung  = outlookNS.Folders["*****@*****.**"].Folders["[Gmail]"].Folders["DevDB"].Folders["Ausbuchung"];
        }
Exemplo n.º 31
0
        void IDTExtensibility2.OnDisconnection(ext_DisconnectMode RemoveMode, ref Array custom)
        {
            RemoveUserInterface();

            if (null != _application)
            {
                _application.Dispose();
                _application = null;
            }
        }
Exemplo n.º 32
0
        private void Initialize()
        {
            outlookApp = new Outlook.Application();

            outlookNS   = outlookApp.GetNamespace("MAPI");
            inboxFolder = outlookNS.GetDefaultFolder(OlDefaultFolders.olFolderInbox);

            items = (Outlook.Items)inboxFolder.Items;
            items.ItemAddEvent +=
                new Outlook.Items_ItemAddEventHandler(items_ItemAdd);
        }
Exemplo n.º 33
0
 void IDTExtensibility2.OnConnection(object Application, ext_ConnectMode ConnectMode, object AddInInst, ref Array custom)
 {
     try
     {
         _outlookApplication = new Outlook.Application(null, Application);
     }
     catch (Exception exception)
     {
         string message = string.Format("An error occured.{0}{0}{1}", Environment.NewLine, exception.Message);
         MessageBox.Show(message, _prodId, MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Exemplo n.º 34
0
 void IDTExtensibility2.OnConnection(object Application, ext_ConnectMode ConnectMode, object AddInInst, ref Array custom)
 {
     try
     {
         _outlookApplication = new Outlook.Application(null, Application);
     }
     catch (Exception exception)
     {
         string message = string.Format("An error occured.{0}{0}{1}", Environment.NewLine, exception.Message);
         MessageBox.Show(message, _prodId, MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Exemplo n.º 35
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;

                Outlook.MailItem mailItem = application.CreateItem(OlItemType.olMailItem) as Outlook.MailItem;
                mailItem.CloseEvent += new NetOffice.OutlookApi.MailItem_CloseEventHandler(mailItem_CloseEvent);

                // BodyFormat is not available in Outlook 2000
                // we check at runtime is property is available
                if (mailItem.EntityIsAvailable("BodyFormat"))
                {
                    mailItem.BodyFormat = OlBodyFormat.olFormatPlain;
                }
                mailItem.Body    = "NetOffice C# Test06" + DateTime.Now.ToLongTimeString();
                mailItem.Subject = "Test06";
                mailItem.Display();
                mailItem.Close(OlInspectorClose.olDiscard);

                if (_closeEventCalled)
                {
                    return(new TestResult(true, DateTime.Now.Subtract(startTime), "", null, ""));
                }
                else
                {
                    return(new TestResult(false, DateTime.Now.Subtract(startTime), "CloseEvent not triggered.", null, ""));
                }
            }
            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();
                }
            }
        }
Exemplo n.º 36
0
        public TestResult DoTest()
        {
            Outlook.Application application = null;
            DateTime startTime = DateTime.Now;
            try
            {
                // start outlook
                application = new Outlook.Application();
                NetOffice.OutlookSecurity.Supress.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)
                {
                    application.Quit();
                    application.Dispose();
                }
                NetOffice.OutlookSecurity.Supress.Enabled = false;
            }
        }
Exemplo n.º 37
0
        public void OnSetOpportunitySuccess(object sender, EventArgs e)
        {
            LateBindingApi.Core.Factory.Initialize();
            Outlook.Application outlookApplication = new Outlook.Application();
            Outlook.MailItem    KatrinEmal         = outlookApplication.CreateItem(OlItemType.olMailItem) as Outlook.MailItem;
            string emailTo = DynamicEntity.EmailAddress;

            if (!string.IsNullOrEmpty(emailTo))
            {
                KatrinEmal.Recipients.Add(emailTo);
            }
            KatrinEmal.Importance = OlImportance.olImportanceNormal;
            KatrinEmal.Display();
        }
        static public outlook.MailItem[] MailItems()
        {
            //Outlook is singleton application, so always return same instance
            outlook.Application app = new outlook.Application();
            NetOffice.OutlookSecurity.Suppress.Enabled = true;
            ArrayList mailItems = new ArrayList();

            foreach (var selection in app.ActiveExplorer().Selection)
            {
                if (selection is outlook.MailItem)
                {
                    mailItems.Add((outlook.MailItem)selection);
                }
            }
            return((outlook.MailItem[])mailItems.ToArray(typeof(outlook.MailItem)));
        }
Exemplo n.º 39
0
        static void Main(string[] args)
        {
            Console.WriteLine("Create 3x Outlook Application");

            Outlook.Application application1 = new Outlook.Application();
            Outlook.Application application2 = new Outlook.Application();
            Outlook.Application application3 = new Outlook.Application();

            Console.WriteLine("Done! Press any key");
            Console.ReadKey();

            application1.Dispose();
            application2.Dispose();
            application3.Dispose();

            Console.WriteLine("Finish! Press any key..");
            Console.ReadKey();
        }
Exemplo n.º 40
0
        private static void TestOutlook()
        {
            Console.WriteLine("Test Outlook Application Utils");

            Outlook.Application application = new Outlook.Application();
            Outlook.Tools.Utils.CommonUtils utils = new Outlook.Tools.Utils.CommonUtils(application);

            bool visible1 = utils.Application.Visible;
            application.Session.GetDefaultFolder(Outlook.Enums.OlDefaultFolders.olFolderInbox).Display();
            System.Threading.Thread.Sleep(3000);
            bool visible2 = utils.Application.Visible;

            application.Quit();
            application.Dispose();

            if(!(false == visible1 && true == visible2))
                throw new Exception("Unexpected outlook visibility");
        }
Exemplo n.º 41
0
        static void Main(string[] args)
        {
            Console.WriteLine("Create 3x Outlook Application");

            Outlook.Application application1 = new Outlook.Application();
            Outlook.Application application2 = new Outlook.Application();
            Outlook.Application application3 = new Outlook.Application();

            Console.WriteLine("Done! Press any key");
            Console.ReadKey();

            application1.Dispose();
            application2.Dispose();
            application3.Dispose();

            Console.WriteLine("Finish! Press any key..");
            Console.ReadKey();
        }
Exemplo n.º 42
0
        private void btnStart_Click(object sender, EventArgs e)
        {
            if (m_app == null)
            {
                m_app = new Outlook.Application();
                Outlook._NameSpace ns = m_app.GetNamespace("MAPI");

                foreach (Outlook.MAPIFolder folder in ns.Folders)
                {
                    txtResults.AppendText(string.Format("{0} - {1}\r\n", folder.Name, folder.DefaultItemType));
                    TraverseFolders(folder);
                }

                Outlook.MAPIFolder selectedFolder = ns.GetFolderFromID("00000000C5B7DEF515463948B280312D7005404A02870000");

                foreach (object oItem in selectedFolder.Items)
                {
                    if (oItem is Outlook.ContactItem)
                    {
                        Outlook.ContactItem item = (Outlook.ContactItem)oItem;

                        txtResults.AppendText(string.Format("{0}/{1}\r\n", item.FirstName, item.LastName));

                        if (string.Equals("LastName", item.LastName))
                        {
                            propertyGrid1.SelectedObject = item;

                            var props = TypeDescriptor.GetProperties(item);
                            foreach (PropertyDescriptor prop in props)
                            {
                                try
                                {
                                    txtResults.AppendText(string.Format("{0} : {1}\r\n", prop.DisplayName, prop.GetValue(item)));
                                }
                                catch (Exception ex)
                                {
                                    Console.WriteLine(ex.Message);
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 43
0
        public void GenerateDayReport()
        {
            try
            {
                LateBindingApi.Core.Factory.Initialize();
                Outlook.Application outlookApplication = new Outlook.Application();

                DateTime    thisDay       = DateTime.Today;
                DateTime    nextDay       = thisDay.AddDays(1);
                IEnumerable taskList      = GetTasks(thisDay);
                var         projectIdList = taskList.AsQueryable().Select("ProjectId").Cast <Guid>().Distinct <Guid>();
                if (projectIdList.ToList().Count <= 0)
                {
                    XtraMessageBox.Show(StringParser.Parse("NoTaskTip"),
                                        StringParser.Parse("Katrin"),
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Information,
                                        MessageBoxDefaultButton.Button1);
                    return;
                }
                foreach (Guid projectId in projectIdList)
                {
                    Outlook.MailItem KatrinEmal = outlookApplication.CreateItem(OlItemType.olMailItem) as Outlook.MailItem;
                    KatrinEmal.Subject = "";
                    string emailTo = "";
                    KatrinEmal.Display();
                    string sourceHtmlBody = KatrinEmal.HTMLBody;
                    string emailBody      = InitEmailMessage(out emailTo, thisDay, nextDay, projectId, taskList);
                    emailBody          += sourceHtmlBody;
                    KatrinEmal.HTMLBody = emailBody;
                    if (!string.IsNullOrEmpty(emailTo))
                    {
                        KatrinEmal.Recipients.Add(emailTo);
                    }
                    KatrinEmal.Importance = OlImportance.olImportanceNormal;
                }
            }
            catch (Exception ex)
            {
                MessageService.ShowException(ex, ResourceService.GetString("EmailExceptionTip"));
            }
        }
Exemplo n.º 44
0
        private void buttonStartExample_Click(object sender, EventArgs e)
        {
            // start outlook
            Outlook.Application outlookApplication = new Outlook.Application();

            // create a new MailItem.
            Outlook.MailItem mailItem = outlookApplication.CreateItem(OlItemType.olMailItem) as Outlook.MailItem;

            // prepare item and send
            mailItem.Recipients.Add(textBoxReciever.Text);
            mailItem.Subject = textBoxSubject.Text;
            mailItem.Body = textBoxBody.Text;
            mailItem.Send();

            // close outlook and dispose
            outlookApplication.Quit();
            outlookApplication.Dispose();

            _hostApplication.ShowFinishDialog("Done!", null);
        }
Exemplo n.º 45
0
        public TestResult DoTest()
        {
            Outlook.Application application = null;
            DateTime startTime = DateTime.Now;
            try
            {
                // start outlook
                application = new Outlook.Application();
                NetOffice.OutlookSecurity.Supress.Enabled = true;

                Outlook.MailItem mailItem = application.CreateItem(OlItemType.olMailItem) as Outlook.MailItem;
                mailItem.CloseEvent += new NetOffice.OutlookApi.MailItem_CloseEventHandler(mailItem_CloseEvent);

                // BodyFormat is not available in Outlook 2000
                // we check at runtime is property is available
                if (mailItem.EntityIsAvailable("BodyFormat"))
                    mailItem.BodyFormat = OlBodyFormat.olFormatPlain;
                mailItem.Body = "NetOffice C# Test06" + DateTime.Now.ToLongTimeString();
                mailItem.Subject = "Test06";
                mailItem.Display();
                mailItem.Close(OlInspectorClose.olDiscard);

                if(_closeEventCalled)
                    return new TestResult(true, DateTime.Now.Subtract(startTime), "", null, "");
                else
                    return new TestResult(false, DateTime.Now.Subtract(startTime), "CloseEvent not triggered.", null, "");
            }
            catch (Exception exception)
            {
                return new TestResult(false, DateTime.Now.Subtract(startTime), exception.Message, exception, "");
            }
            finally
            {
                if (null != application)
                {
                    application.Quit();
                    application.Dispose();
                }
                NetOffice.OutlookSecurity.Supress.Enabled = false;
            }
        }
Exemplo n.º 46
0
        public void RunExample()
        {
            // start outlook
            Outlook.Application outlookApplication = new Outlook.Application();

            // create a new TaskItem.
            Outlook.TaskItem newTask = outlookApplication.CreateItem(OlItemType.olTaskItem) as Outlook.TaskItem;

            // Configure the task at hand and save it.
            newTask.Subject = "Don't forget to check for NetOffice.DeveloperToolbox updates";
            newTask.Body = "check updates here: http://netoffice.codeplex.com/releases";
            newTask.DueDate = DateTime.Now;
            newTask.Importance = OlImportance.olImportanceHigh;
            newTask.Save();

            // close outlook and dispose
            outlookApplication.Quit();
            outlookApplication.Dispose();

            _hostApplication.ShowFinishDialog("Done!", null);
        }
Exemplo n.º 47
0
        private void buttonStartExample_Click(object sender, EventArgs e)
        {
            try
            {
                Outlook.Application application = null;

                object nativeProxy = System.Runtime.InteropServices.Marshal.GetActiveObject("Outlook.Application");
                application = new Outlook.Application(null, nativeProxy);

                textBoxLog.Clear();
                textBoxLog.AppendText("we got running outlook instance\r\n");
                textBoxLog.AppendText("outlook version is " + application.Version);

                // instance was already running at start. we dispose references but not quit application
                application.Dispose();
            }
            catch (System.Runtime.InteropServices.COMException exception)
            {
                _hostApplication.ShowErrorDialog(null, exception);
            }            
        }
Exemplo n.º 48
0
        private void buttonStartExample_Click(object sender, EventArgs e)
        {
            // start outlook
            Outlook.Application outlookApplication = new Outlook.Application();

            // create MailItem and register close event
            Outlook.MailItem mailItem = outlookApplication.CreateItem(OlItemType.olMailItem) as Outlook.MailItem;
            mailItem.CloseEvent += new NetOffice.OutlookApi.MailItem_CloseEventHandler(mailItem_CloseEvent);

            // BodyFormat is not available in Outlook 2000, we check at runtime the property is available
            if (mailItem.EntityIsAvailable("BodyFormat"))
                mailItem.BodyFormat = OlBodyFormat.olFormatPlain;
            mailItem.Body = "ExampleBody";
            mailItem.Subject = "ExampleSubject";
            mailItem.Display();
            mailItem.Close(OlInspectorClose.olDiscard);

            // close outlook and dispose
            outlookApplication.Quit();
            outlookApplication.Dispose();
        }
Exemplo n.º 49
0
        public void RunExample()
        {
            // start outlook
            Outlook.Application outlookApplication = new Outlook.Application();

            // SendAndReceive is supported from Outlook 2007 or higher
            // we check at runtime the feature is available
            if (outlookApplication.Session.EntityIsAvailable("SendAndReceive"))
            {
                // one simple call
                outlookApplication.Session.SendAndReceive(false);
            }
            else
            {
                _hostApplication.ShowErrorDialog("This version of MS-Outlook doesnt support SendAndReceive.", null);
            }

            // close outlook and dispose
            outlookApplication.Quit();
            outlookApplication.Dispose();

		 _hostApplication.ShowFinishDialog("Done!", null);
        }
Exemplo n.º 50
0
        private void buttonStartExample_Click(object sender, EventArgs e)
        {
            // start outlook
            Outlook.Application outlookApplication = new Outlook.Application();

            // enum contacts 
            int i = 0;
            Outlook.MAPIFolder contactFolder = outlookApplication.Session.GetDefaultFolder(OlDefaultFolders.olFolderContacts);
            foreach (COMObject item in contactFolder.Items)
            {
                Outlook.ContactItem contact = item as Outlook.ContactItem;
                if (null != contact)
                {
                    i++;
                    ListViewItem listItem = listViewContacts.Items.Add(i.ToString());
                    listItem.SubItems.Add(contact.CompanyAndFullName);
                }
            }

            // close outlook and dispose
            outlookApplication.Quit();
            outlookApplication.Dispose();
        }
Exemplo n.º 51
0
        private void buttonStartExample_Click(object sender, EventArgs e)
        {
            // start outlook
            _outlookApplication = new Outlook.Application();

            Office.CommandBar commandBar = null;
            Office.CommandBarButton commandBarBtn = null;

            Outlook._NameSpace outlookNS = _outlookApplication.GetNamespace("MAPI");
            Outlook.MAPIFolder inboxFolder = outlookNS.GetDefaultFolder(OlDefaultFolders.olFolderInbox);
            inboxFolder.Display();

            // add a commandbar popup
            Office.CommandBarPopup commandBarPopup = (Office.CommandBarPopup)_outlookApplication.ActiveExplorer().CommandBars["Menu Bar"].Controls.Add(MsoControlType.msoControlPopup, System.Type.Missing, System.Type.Missing, System.Type.Missing, true);
            commandBarPopup.Caption = "commandBarPopup";

            #region few words, how to access the picture
            /*
             you can see we use an own icon via .PasteFace()
             is not possible from outside process boundaries to use the PictureProperty directly
             the reason for is IPictureDisp: http://support.microsoft.com/kb/286460/de
             its not important is early or late binding or managed or unmanaged, the behaviour is always the same
             For example, a COMAddin running as InProcServer and can access the Picture Property
            */
            #endregion

            #region CommandBarButton

            // add a button to the popup
            commandBarBtn = (Office.CommandBarButton)commandBarPopup.Controls.Add(MsoControlType.msoControlButton, System.Type.Missing, System.Type.Missing, System.Type.Missing, true);
            commandBarBtn.Style = MsoButtonStyle.msoButtonIconAndCaption;
            commandBarBtn.Caption = "commandBarButton";
            Clipboard.SetDataObject(HostApplication.DisplayIcon.ToBitmap());
            commandBarBtn.PasteFace();
            commandBarBtn.ClickEvent += new Office.CommandBarButton_ClickEventHandler(commandBarBtn_Click);

            #endregion

            #region Create a new toolbar

            // add a new toolbar
            commandBar = _outlookApplication.ActiveExplorer().CommandBars.Add("MyCommandBar", MsoBarPosition.msoBarTop, false, true);
            commandBar.Visible = true;

            // add a button to the toolbar
            commandBarBtn = (Office.CommandBarButton)commandBar.Controls.Add(MsoControlType.msoControlButton, System.Type.Missing, System.Type.Missing, System.Type.Missing, true);
            commandBarBtn.Style = MsoButtonStyle.msoButtonIconAndCaption;
            commandBarBtn.Caption = "commandBarButton";
            commandBarBtn.FaceId = 3;
            commandBarBtn.ClickEvent += new Office.CommandBarButton_ClickEventHandler(commandBarBtn_Click);

            // add a dropdown box to the toolbar
            commandBarPopup = (Office.CommandBarPopup)commandBar.Controls.Add(MsoControlType.msoControlPopup, System.Type.Missing, System.Type.Missing, System.Type.Missing, true);
            commandBarPopup.Caption = "commandBarPopup";

            // add a button to the popup, we use an own icon for the button
            commandBarBtn = (Office.CommandBarButton)commandBarPopup.Controls.Add(MsoControlType.msoControlButton, System.Type.Missing, System.Type.Missing, System.Type.Missing, true);
            commandBarBtn.Style = MsoButtonStyle.msoButtonIconAndCaption;
            commandBarBtn.Caption = "commandBarButton";
            Clipboard.SetDataObject(HostApplication.DisplayIcon.ToBitmap());
            commandBarBtn.PasteFace();
            commandBarBtn.ClickEvent += new Office.CommandBarButton_ClickEventHandler(commandBarBtn_Click);

            #endregion

            // set buttons
            buttonStartExample.Enabled = false;
            buttonQuitExample.Enabled = true;
        }
Exemplo n.º 52
0
        public TestResult DoTest()
        {
            Outlook.Application application = null;
            DateTime startTime = DateTime.Now;
            try
            {
                Bitmap iconBitmap = new Bitmap(System.Reflection.Assembly.GetAssembly(this.GetType()).GetManifestResourceStream("OutlookTestsCSharp.Test07.bmp"));

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

                Office.CommandBar commandBar;
                Office.CommandBarButton commandBarBtn;

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

                // add a commandbar popup
                Office.CommandBarPopup commandBarPopup = (Office.CommandBarPopup)application.ActiveExplorer().CommandBars["Menu Bar"].Controls.Add(MsoControlType.msoControlPopup, System.Type.Missing, System.Type.Missing, System.Type.Missing, true);
                commandBarPopup.Caption = "commandBarPopup";
  
                #region CommandBarButton

                // add a button to the popup
                commandBarBtn = (Office.CommandBarButton)commandBarPopup.Controls.Add(MsoControlType.msoControlButton, System.Type.Missing, System.Type.Missing, System.Type.Missing, true);
                commandBarBtn.Style = MsoButtonStyle.msoButtonIconAndCaption;
                commandBarBtn.Caption = "commandBarButton";
                Clipboard.SetDataObject(iconBitmap);
                commandBarBtn.PasteFace();
                commandBarBtn.ClickEvent += new Office.CommandBarButton_ClickEventHandler(commandBarBtn_Click);

                #endregion

                #region Create a new toolbar

                // add a new toolbar
                commandBar = application.ActiveExplorer().CommandBars.Add("MyCommandBar", MsoBarPosition.msoBarTop, false, true);
                commandBar.Visible = true;

                // add a button to the toolbar
                commandBarBtn = (Office.CommandBarButton)commandBar.Controls.Add(MsoControlType.msoControlButton, System.Type.Missing, System.Type.Missing, System.Type.Missing, true);
                commandBarBtn.Style = MsoButtonStyle.msoButtonIconAndCaption;
                commandBarBtn.Caption = "commandBarButton";
                commandBarBtn.FaceId = 3;
                commandBarBtn.ClickEvent += new Office.CommandBarButton_ClickEventHandler(commandBarBtn_Click);

                // add a dropdown box to the toolbar
                commandBarPopup = (Office.CommandBarPopup)commandBar.Controls.Add(MsoControlType.msoControlPopup, System.Type.Missing, System.Type.Missing, System.Type.Missing, true);
                commandBarPopup.Caption = "commandBarPopup";

                // add a button to the popup, we use an own icon for the button
                commandBarBtn = (Office.CommandBarButton)commandBarPopup.Controls.Add(MsoControlType.msoControlButton, System.Type.Missing, System.Type.Missing, System.Type.Missing, true);
                commandBarBtn.Style = MsoButtonStyle.msoButtonIconAndCaption;
                commandBarBtn.Caption = "commandBarButton";
                Clipboard.SetDataObject(iconBitmap);
                commandBarBtn.PasteFace();
                commandBarBtn.ClickEvent += new Office.CommandBarButton_ClickEventHandler(commandBarBtn_Click);

                #endregion
              
                return new TestResult(true, DateTime.Now.Subtract(startTime), "", null, "");
            }
            catch (Exception exception)
            {
                return new TestResult(false, DateTime.Now.Subtract(startTime), exception.Message, exception, "");
            }
            finally
            {
                if (null != application)
                {
                    application.Quit();
                    application.Dispose();
                }
                NetOffice.OutlookSecurity.Supress.Enabled = false;
            }
        }
Exemplo n.º 53
0
 private void CreateOfficeApplication()
 {
     switch (_officeApp)
     {
         case "Excel":
             _excelApplication = new Excel.Application("Excel.Application");
             break;
         case "Word":
             _wordApplication = new Word.Application("Word.Application");
             break;
         case "Outlook":
             _outlookApplication = new Outlook.Application("Outlook.Application");
             break;
         case "Power Point":
             _powerpointApplication = new PowerPoint.Application("PowerPoint.Application");
             break;
         case "Access":
             _accessApplication = new Access.Application("Access.Application");
             break;
         case "Project":
             _projectApplication = new Project.Application("MSProject.Application");
             break;
         case "Visio":
             _visioApplication = new Visio.Application("Visio.Application");
             break;
         default:
             throw new ArgumentOutOfRangeException("officeApp");
     }
 }
Exemplo n.º 54
0
        public void ClickEmail()
        {
            try
            {
                var type = Data.ProviderCollection.GetType(this.Provider, this.Type);
                if (type == null) return;
                string mails = type.Email;
                if (string.IsNullOrEmpty(mails)) return;
                if (!mails.Contains("@"))
                { MessageBox.Show(mails.ToString(), "მისამართი", MessageBoxButtons.OK, MessageBoxIcon.Information); return; }
                string[] mailsarray = mails.Split(';');
                string subject = "თანხის " + this.Type + " " + this.From + " (INC" + this.Inc + ")";

                using (Outlook.Application app = new Outlook.Application())
                {
                    var mail = (Outlook.MailItem)app.CreateItem(Outlook.Enums.OlItemType.olMailItem);
                    var mailIndex = mails.IndexOf(";");
                    if (mailIndex == -1)
                        mail.To = mails;
                    else
                    {
                        mail.To = mails.Substring(0, mailIndex + 1);
                        mail.CC += mails.Substring(mailIndex);
                    }
                    mail.CC += ";" + GetEMails();
                    mail.Subject = subject;
                    mail.HTMLBody = File.ReadAllText(Path.Combine(Application.StartupPath, "conf\\OutlookBody.html")) + mail.HTMLBody;
                    string scanpath = GetScanImgPath();
                    if (File.Exists(scanpath))
                        mail.Attachments.Add(scanpath);
                    mail.Display();
                }
            }
            catch (Exception ex)
            {
                ErrorBox.Show(ex.Message, ex.StackTrace);
            }
        }
Exemplo n.º 55
0
 public OutlookToolkitApi()
 {
     app = new Outlook.Application();
     ns = app.GetNamespace("MAPI");
 }