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; } }
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; } }
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); }
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(); }
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); }
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(); } } }
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(); }
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; } }
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(); } } }
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(); } } }
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; } }
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(); }
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(); }
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(); }
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(); } } }
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(); }
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(); } } }
private void buttonQuitExample_Click(object sender, EventArgs e) { _outlookApplication.Quit(); _outlookApplication.Dispose(); buttonStartExample.Enabled = true; buttonQuitExample.Enabled = false; }
private void btnStop_Click(object sender, EventArgs e) { if (m_app != null) { m_app.Dispose(); } m_app = null; }
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); } } }
void IDTExtensibility2.OnDisconnection(ext_DisconnectMode RemoveMode, ref Array custom) { RemoveUserInterface(); if (null != _application) { _application.Dispose(); _application = null; } }
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(); } } }
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; } }
private void Addin_OnDisconnection(ext_DisconnectMode RemoveMode, ref Array custom) { try { if (null != _outlookApplication) { _outlookApplication.Dispose(); } } catch (Exception exception) { // 处理 } }
void IDTExtensibility2.OnDisconnection(ext_DisconnectMode RemoveMode, ref Array custom) { try { if (null != _outlookApplication) { _outlookApplication.Dispose(); } } 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); } }
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"); }
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(); }
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); }
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); }
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; } }
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); } }
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(); }
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); }
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"); } }
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); }
public TestResult DoTest() { Outlook.Application application = null; DateTime startTime = DateTime.Now; try { // start outlook application = new Outlook.Application(true); 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) { if (!application.FromProxyService) { application.Quit(); } application.Dispose(); } } }
public TestResult DoTest() { Outlook.Application application = null; DateTime startTime = DateTime.Now; try { // start outlook application = COMObject.CreateByRunningInstance <Outlook.Application>(COMObjectCreateOptions.CreateNewCore); NetOffice.OutlookSecurity.Suppress.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) { if (!application.FromProxyService) { application.Quit(); } application.Dispose(); } } }
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); }
private void buttonStartExample_Click(object sender, EventArgs e) { // start outlook by trying to access running application first Outlook.Application outlookApplication = COMObject.CreateByRunningInstance <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 if (!outlookApplication.FromProxyService) { outlookApplication.Quit(); } outlookApplication.Dispose(); HostApplication.ShowFinishDialog("Done!", null); }
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(); }
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; } }
public void Dispose() { switch (_officeApp) { case "Excel": _excelApplication.Dispose(); break; case "Word": _wordApplication.Dispose(); break; case "Outlook": _outlookApplication.Dispose(); break; case "Power Point": _powerpointApplication.Dispose(); break; case "Access": _accessApplication.Dispose(); break; case "Project": _accessApplication.Dispose(); break; case "Visio": _accessApplication.Dispose(); break; default: throw new ArgumentOutOfRangeException("officeApp"); } }
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; } }