private void adxOutlookEvents_ExplorerFolderSwitch(object sender, object explorer) { Outlook._Explorer activeExplorer = OutlookApp.ActiveExplorer(); if (activeExplorer != null) { try { Outlook.MAPIFolder folder = activeExplorer.CurrentFolder; if (folder != null) { try { Outlook.Items items = folder.Items; if (items != null) { try { btnMessage.Enabled = (items.Count != 0); } finally { Marshal.ReleaseComObject(items); } } } finally { Marshal.ReleaseComObject(folder); } } } finally { Marshal.ReleaseComObject(activeExplorer); } } }
private void ThisAddIn_Startup(object sender, System.EventArgs e) { Outlook.MAPIFolder inbox = Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox); items = inbox.Items; items.ItemAdd += new Outlook.ItemsEvents_ItemAddEventHandler(InboxFolderItemAdded); }
private ArrayList RecurringItems() { // Filter all the objects we are looking for. Outlook.AppointmentItem appoinmentItem = null; Outlook.MAPIFolder folder = OutlookApplication.Session.GetDefaultFolder( Outlook.OlDefaultFolders.olFolderCalendar) as Outlook.MAPIFolder; // Use a Jet Query to filter the details we need initially between // the two spcified dates. string dateFilter = String.Format( CultureConstants.DefaultCulture, "[Start] >= '{0:g}' and [End] <= '{1:g}'", startDate, endDate); Outlook.Items calendarItems = folder.Items.Restrict(dateFilter); calendarItems.Sort("[Start]", Type.Missing); calendarItems.IncludeRecurrences = true; // Must use 'like' comparison for Find/FindNext string subjectFilter = String.Empty; if (String.IsNullOrEmpty(subject)) { subjectFilter = "@SQL=" + "\"" + "urn:schemas:httpmail:subject" + "\"" + " like '%" + subject + "%'"; } else { subjectFilter = "@SQL=" + "\"" + "urn:schemas:httpmail:subject" + "\"" + " <> '!@#'"; } // Use Find and FindNext methods to get all the items. ArrayList resultArray = new ArrayList(); appoinmentItem = calendarItems.Find(subjectFilter) as Outlook.AppointmentItem; while (appoinmentItem != null) { resultArray.Add(appoinmentItem); // Find the next appointment. appoinmentItem = calendarItems.FindNext() as Outlook.AppointmentItem; } return(resultArray); }
private void DoEnumContacts() { if (btnMode.State == AddinExpress.MSO.ADXMsoButtonState.adxMsoButtonDown) { securityManager1.DisableOOMWarnings = true; } try { Outlook.NameSpace namespace_ = OutlookApp.GetNamespace("MAPI"); if (namespace_ != null) { try { Outlook.MAPIFolder folder = namespace_.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts); if (folder != null) { try { ContactsForm frmContacts = new ContactsForm(); try { Outlook.Items items = folder.Items; if (items != null) { try { for (int i = 1; i <= items.Count; i++) { Outlook.ContactItem contact = items.Item(i) as Outlook.ContactItem; if (contact != null) { try { if (!string.IsNullOrEmpty(contact.Email1DisplayName)) { DataRow newRow = frmContacts.dsContacts.Tables["Contacts"].NewRow(); newRow["DisplayName"] = contact.Email1DisplayName; newRow["Address"] = contact.Email1Address; newRow["AddressType"] = contact.Email1AddressType; frmContacts.dsContacts.Tables["Contacts"].Rows.Add(newRow); } if (!string.IsNullOrEmpty(contact.Email2DisplayName)) { DataRow newRow = frmContacts.dsContacts.Tables["Contacts"].NewRow(); newRow["DisplayName"] = contact.Email2DisplayName; newRow["Address"] = contact.Email2Address; newRow["AddressType"] = contact.Email2AddressType; frmContacts.dsContacts.Tables["Contacts"].Rows.Add(newRow); } if (!string.IsNullOrEmpty(contact.Email3DisplayName)) { DataRow newRow = frmContacts.dsContacts.Tables["Contacts"].NewRow(); newRow["DisplayName"] = contact.Email3DisplayName; newRow["Address"] = contact.Email3Address; newRow["AddressType"] = contact.Email3AddressType; frmContacts.dsContacts.Tables["Contacts"].Rows.Add(newRow); } } finally { Marshal.ReleaseComObject(contact); } } } } finally { Marshal.ReleaseComObject(items); } } } catch { } frmContacts.ShowDialog(); frmContacts.Dispose(); } finally { Marshal.ReleaseComObject(folder); } } } finally { Marshal.ReleaseComObject(namespace_); } } } finally { if (btnMode.State == AddinExpress.MSO.ADXMsoButtonState.adxMsoButtonDown) { securityManager1.DisableOOMWarnings = false; } } }
private void ThisAddIn_Startup(object sender, System.EventArgs e) { Application.ItemSend += new Microsoft.Office.Interop.Outlook.ApplicationEvents_11_ItemSendEventHandler(ItemSend); sentMailItems = Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMail).Items; sentMailItems.ItemAdd += new Outlook.ItemsEvents_ItemAddEventHandler(Items_ItemAdd); }