private MailItem GetSelectedMailItem() { foreach (var item in _app.ActiveExplorer().Selection) { return((MailItem)item); } throw new NullReferenceException("Cant get selected email."); }
public void ArchiveButton_Click(Office.IRibbonControl control) { if (_outlook.ActiveWindow() == _outlook.ActiveExplorer()) { HandleExplorerWindow(); } else { HandleEmailWindow(); } }
public IEnumerable <MailItem> GetItemInCurrentSelectedFolder() { var list = new List <MailItem>(); var oLFolder = _app.ActiveExplorer().CurrentFolder; foreach (var item in oLFolder.Items) { if (item is MailItem) { list.Add(item as MailItem); } } return(list); }
private void ThisAddIn_Startup(object sender, System.EventArgs e) { // Create the AppData and ImageCache folders, if needed Directory.CreateDirectory(Common.appFolder); Directory.CreateDirectory(Common.imageCacheFolder); // Get a List of all files still in the Image Cache string[] allFiles = Directory.GetFiles(Common.imageCacheFolder); // Clear the Image Cache, if any images exist if (allFiles.Length > 0) { for (int i = allFiles.Length - 1; i >= 0; i--) { File.Delete(allFiles[i]); } } // Get the Outlook Namespace so we can monitor incoming messages outlookNameSpace = this.Application.GetNamespace("MAPI"); inbox = outlookNameSpace.GetDefaultFolder( Outlook.OlDefaultFolders.olFolderInbox); // Get a list of inbox items and add an event flag for when new items are added (a message is received) // EVENT IS CURRENTLY DISABLED, AUTOMATED CONVERSION CAUSING TOO MUCH MEMORY OVERHEAD //items = inbox.Items; //items.ItemAdd += // new Outlook.ItemsEvents_ItemAddEventHandler(Items_ItemAdd); // Set Event to Trigger any time a new window takes focus currentExplorer = Application.ActiveExplorer(); currentExplorer.SelectionChange += new Outlook .ExplorerEvents_10_SelectionChangeEventHandler (ExplorerChanged); }
private void DecryptButton_Click(Office.CommandBarButton Ctrl, ref bool CancelDefault) { // Get the selected item in Outlook and determine its type. Outlook.Selection outlookSelection = Application.ActiveExplorer().Selection; if (outlookSelection.Count <= 0) return; object selectedItem = outlookSelection[1]; Outlook.MailItem mailItem = selectedItem as Outlook.MailItem; if (mailItem == null) { MessageBox.Show( "OutlookGnuPG can only decrypt mails.", "Invalid Item Type", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // Force open of mailItem with auto decrypt. _autoDecrypt = true; mailItem.Display(true); // DecryptEmail(mailItem); }
private void ThisAddIn_Startup(object sender, System.EventArgs e) { _currentExplorer = Application.ActiveExplorer(); _currentExplorer.SelectionChange += CurrentExplorer_Event; ((Outlook.ApplicationEvents_11_Event)Application).Quit += ThisAddIn_Quit; MainController.OnAddinStartup(_currentExplorer.Session.SyncObjects[1]); }
void Explorer_SelectionChange() { WriteToLog("Explorer_SelectionChange"); Outlook.Explorer explorer; Outlook.MailItem mailItem; string jira = string.Empty; if ((explorer = Application.ActiveExplorer()) == null || explorer.Selection == null || explorer.Selection.Count == 0 || (mailItem = explorer.Selection[1] as Outlook.MailItem) == null || mailItem.MessageClass == CustomMessageClass /*|| (jira=GetMailItemHeaderItem(mailItem, regexJira)) == string.Empty*/) { return; } //WriteToLog(string.Format("{0} -> call ChangeMessageClass()", jira)); ChangeMessageClass(mailItem); }
public CalDavSynchronizerToolBar (Application application, ComponentContainer componentContainer, object missing) { _componentContainer = componentContainer; var toolBar = application.ActiveExplorer().CommandBars.Add ("CalDav Synchronizer", MsoBarPosition.msoBarTop, false, true); var toolBarBtnOptions = (CommandBarButton) toolBar.Controls.Add (1, missing, missing, missing, missing); toolBarBtnOptions.Style = MsoButtonStyle.msoButtonIconAndCaption; toolBarBtnOptions.Caption = "Options"; toolBarBtnOptions.FaceId = 222; // builtin icon: hand hovering above a property list toolBarBtnOptions.Tag = "View or set CalDav Synchronizer options"; toolBarBtnOptions.Click += ToolBarBtn_Options_OnClick; _toolBarBtnSyncNow = (CommandBarButton) toolBar.Controls.Add (1, missing, missing, missing, missing); _toolBarBtnSyncNow.Style = MsoButtonStyle.msoButtonIconAndCaption; _toolBarBtnSyncNow.Caption = "Synchronize"; _toolBarBtnSyncNow.FaceId = 107; // builtin icon: lightning hovering above a calendar table _toolBarBtnSyncNow.Tag = "Synchronize now"; _toolBarBtnSyncNow.Click += ToolBarBtn_SyncNow_OnClick; var toolBarBtnAboutMe = (CommandBarButton) toolBar.Controls.Add (1, missing, missing, missing, missing); toolBarBtnAboutMe.Style = MsoButtonStyle.msoButtonIconAndCaption; toolBarBtnAboutMe.Caption = "About"; toolBarBtnAboutMe.FaceId = 487; // builtin icon: blue round sign with "i" letter toolBarBtnAboutMe.Tag = "About CalDav Synchronizer"; toolBarBtnAboutMe.Click += ToolBarBtn_About_OnClick; toolBar.Visible = true; }
/// <summary> /// Add SyncBar if it is not there. /// When creating a command bar or a button, Outlook just has the meta data of the GUI updated. So even after the assembly of the addin /// is removed, the command bar along with the buttons are still there. /// http://www.add-in-express.com/docs/net-commandbar-tips.php#visibility-rules /// </summary> void AddSyncBar() { Outlook.Explorer explorer = Application.ActiveExplorer(); IEnumerable <Office.CommandBar> bars = explorer.CommandBars.OfType <Office.CommandBar>().Where(item => item.Name == syncBarName); syncBar = bars.FirstOrDefault(); if (syncBar == null) { syncBar = explorer.CommandBars.Add(syncBarName, Office.MsoBarPosition.msoBarTop, false, false); } #if DEBUG ClearButtons(); #endif syncButton = GetButton("Fonlow.SyncML.Sync", "Sync", "Display the sync center", OutlookSyncMLAddIn.Properties.Resources.sync16); syncButton.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(syncButton_Click); optionsButton = GetButton("Fonlow.SyncML.Options", "Options", "Display the Options of sync", OutlookSyncMLAddIn.Properties.Resources.Settings16); optionsButton.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(optionsButton_Click); syncBar.Visible = true; #if DEBUG logButton = GetButton("Fonlow.SyncML.Log", "Log", "Log window", null); logButton.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(logButton_Click); #endif }
/// <summary> /// Hard-deletes all meetings newer than today that the add-in created. /// </summary> public int DeleteFutureMeetings() { Log.WriteDebug("Deleting all future meetings"); Outlook.MAPIFolder calendar = Application.ActiveExplorer().Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar); Outlook.Items items = calendar.Items; // start deleting from 11:59pm the previous night to capture the all-day events DateTime startDate = DateTime.Now.Date.AddMinutes(-1); string filter = String.Format("[Start] >= '{0}' and [MessageClass] = '{1}'", String.Format("{0} {1}", startDate.ToShortDateString(), startDate.ToShortTimeString()), CUSTOM_MESSAGE_CLASS); items = items.Restrict(filter); // https://msdn.microsoft.com/en-us/library/office/microsoft.office.interop.outlook._appointmentitem.delete(v=office.15).aspx // https://social.msdn.microsoft.com/Forums/office/en-US/53a07e5d-ab16-4930-90bf-52215f084d59/appointmentitemrecipientsremoveindex-question?forum=outlookdev // Seriously Outlook Object Model? So the index starts at 1 and we have to always decrement instead of increment. for (int j = items.Count; j >= 1; j--) { AppointmentItem item = items[j] as AppointmentItem; item.Delete(); } PurgeMeetingsFromDeletedItems(); Log.WriteEntry("Deleted all future meetings"); return(items.Count); }
/// <summary>Handles the start up event of the add-in.</summary> /// <remarks>Subscribes to the folder switch event of the active /// explorer.</remarks> private void ThisAddIn_Startup(object sender, System.EventArgs e) { explorer = Application.ActiveExplorer(); explorer.FolderSwitch += new Outlook.ExplorerEvents_10_FolderSwitchEventHandler( explorer_FolderSwitch); }
private void ExplorerSelectionChange() { _activeExplorer = Application.ActiveExplorer(); if (_activeExplorer == null) { return; } Outlook.Selection selection = _activeExplorer.Selection; if (_ribbon != null) { if (selection != null && selection.Count == 1 && selection[1] is Outlook.MailItem) { // one Mail object is selected Outlook.MailItem selectedMail = selection[1] as Outlook.MailItem; // (collection is 1-indexed) // tell the ribbon what our currently selected email is by setting this custom property, and run code against it _ribbon.CurrentEmail = selectedMail; } else { _ribbon.CurrentEmail = null; } _ribbon.SetRibbonButtonStatus(_ribbon.CurrentEmail != null); } }
public IEnumerable <MailItem> GetSelectedEmails() { foreach (MailItem email in outlookApp.ActiveExplorer().Selection) { yield return(email); } }
private void AppendTask_Click(CommandBarButton Ctrl, ref bool CancelDefault) { SelectFolder(selected => { // NOTE: If we don't pin the COM object here, the RCW will free it when // we leave scope. We'll unpin it after the task dialog comes back. Pinned.Add(selected); System.Action Unpin = () => Pinned.Remove(selected); try { // Get the mail message in focus var SelectedItem = Application.ActiveExplorer().Selection[1] as MailItem; // request that the user choose a task to append it to SelectTaskForm.AskUserForTask(selected.Folder.Items, task => { task.Attachments.Add(SelectedItem); // FUTURE: extract more data from the email to generate the task task.Display(false); Unpin(); }, () => { // user clicked cancel Unpin(); }); } catch (System.Exception ex) { // COMException for 'access deined' with reasonably friendly error message MessageBox.Show(ex.Message, "TaskFromMail", MessageBoxButtons.OK, MessageBoxIcon.Error); } }); }
private void CreateTask_Click(CommandBarButton Ctrl, ref bool CancelDefault) { SelectFolder(selected => { try { // FUTURE flag message with GREEN if posible // Get the mail message in focus var SelectedItem = Application.ActiveExplorer().Selection[1] as MailItem; // create a new task _in_ the specified folder var task = selected.Folder.Items.Add(OlItemType.olTaskItem) as TaskItem; // space out the attachment a bit task.Body = "\n\n\n"; // Attach the email message to the new task task.Attachments.Add(SelectedItem); // Give the task a default subject task.Subject = SelectedItem.Subject; // FUTURE: extract more data from the email to generate the task task.Display(false); } catch (System.Exception ex) { // COMException for 'access deined' with reasonably friendly error message MessageBox.Show(ex.Message, "TaskFromMail", MessageBoxButtons.OK, MessageBoxIcon.Error); } }); }
void Explorer_SelectionChange() { WriteToLog("Explorer_SelectionChange"); Outlook.Explorer explorer; if ((explorer = Application.ActiveExplorer()) == null) { return; } #if SHOW_PATH if (explorer.CurrentFolder != null) { WriteToLog(string.Format("Name: {0} FolderPath: {1} FullFolderPath: {2} WebViewOn: {3}", explorer.CurrentFolder.Name, explorer.CurrentFolder.FolderPath, explorer.CurrentFolder.FullFolderPath, explorer.CurrentFolder.WebViewOn)); } #endif Outlook.MailItem mailItem; if (explorer.Selection == null || explorer.Selection.Count == 0 || (mailItem = explorer.Selection[1] as Outlook.MailItem) == null || mailItem.MessageClass == CustomMessageClass /*|| GetMailItemHeaderFrom(mailItem)==string.Empty*/) { return; } ChangeMessageClass(mailItem); }
private void CreateHtmlFolder() { Outlook.MAPIFolder newView = null; string viewName = "HtmlView"; Outlook.MAPIFolder inBox = (Outlook.MAPIFolder) this.Application.ActiveExplorer().Session.GetDefaultFolder(Outlook .OlDefaultFolders.olFolderInbox); Outlook.Folders searchFolders = (Outlook.Folders)inBox.Folders; bool foundView = false; foreach (Outlook.MAPIFolder searchFolder in searchFolders) { if (searchFolder.Name == viewName) { newView = inBox.Folders[viewName]; foundView = true; } } //Outlook.OlDefaultFolders.olFolderInbox if (!foundView) { newView = (Outlook.MAPIFolder)inBox.Folders. Add("HtmlView", Outlook.OlDefaultFolders.olFolderInbox); newView.WebViewURL = "https://www.microsoft.com"; newView.WebViewOn = true; } Application.ActiveExplorer().SelectFolder(newView); Application.ActiveExplorer().CurrentFolder.Display(); }
private void AddFolderToFavorites(Outlook.MAPIFolder folder) { var pane = Application.ActiveExplorer().NavigationPane; var module = pane.Modules.GetNavigationModule(Outlook.OlNavigationModuleType.olModuleMail) as Outlook.MailModule; var navGroup = module.NavigationGroups.GetDefaultNavigationGroup(Outlook.OlGroupType.olFavoriteFoldersGroup); navGroup.NavigationFolders.Add(folder); }
private void ThisAddIn_Startup(object sender, EventArgs e) { _explorers = Application.Explorers; _explorers.NewExplorer += new Outlook.ExplorersEvents_NewExplorerEventHandler(NewExplorerEventHandler); _activeExplorer = Application.ActiveExplorer(); _activeExplorer.SelectionChange += new Outlook.ExplorerEvents_10_SelectionChangeEventHandler(ExplorerSelectionChange); }
public MailSelection() { _outlookApplication = new Application(); _ns = _outlookApplication.GetNamespace("MAPI"); _inspector = _outlookApplication.ActiveInspector(); _explorer = _outlookApplication.ActiveExplorer(); Logger.LogInfo("EMAILTRACKING: Initialised Mail Selection"); }
private void ThisAddIn_Startup(object sender, System.EventArgs e) { //Create a new button on Explorer to show the form region. Office.CommandBar CustomBar = Application.ActiveExplorer().CommandBars.Add("CSImportedFormRegion", Office.MsoBarPosition.msoBarTop, false, true); CustomBar.Visible = true; btnCreateCustomItem = CustomBar.Controls.Add(Office.MsoControlType.msoControlButton, missing, missing, missing, true) as Office.CommandBarButton; btnCreateCustomItem.Caption = "Create A Custom Item"; btnCreateCustomItem.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(btnCreateCustomItem_Click); }
/// <summary> /// Opens the calendar with redmine time entries /// </summary> public void OpenCalendar() { var primaryCalendar = this.Application.ActiveExplorer().Session.GetDefaultFolder(OlDefaultFolders.olFolderCalendar); Application.ActiveExplorer().SelectFolder(primaryCalendar.Folders[CalendarName]); Application.ActiveExplorer().CurrentFolder.Display(); var view = primaryCalendar.CurrentView; }
private bool CommandBarExists(string name) { try { string text1 = Application.ActiveExplorer().CommandBars[name].Name; return(true); } catch (System.Exception) { return(false); } }
private bool CommandBarExists(string name) { try { var explorer = Application.ActiveExplorer(); return(explorer != null && explorer.CommandBars[name] != null); } catch (System.Exception) { return(false); } }
public void Open(bool display) { Application = new Application(); nameSpace = Application.GetNamespace("MAPI"); var defFolder = nameSpace.GetDefaultFolder(OlDefaultFolders.olFolderInbox); if (display) { defFolder.Display(); Application.ActiveExplorer().Activate(); } }
private void Explorer_SelectionChange() { if (Application.ActiveExplorer().Selection.Count > 0) { Object selectedObject = Application.ActiveExplorer().Selection[1]; if (Ribbon != null) { Ribbon.InvalidateControl("buttonMailReport"); } } }
private void ThisAddIn_Startup(object sender, System.EventArgs e) { _taskPaneControl = new TaskGTDViewWPFHost(); _taskPaneControl.MailClicked += new TaskGTDView.MailClickedEventHandler(_taskPaneControl_MailClicked); _customTaskPane = this.CustomTaskPanes.Add(_taskPaneControl as UserControl, "Task info"); _customTaskPane.Visible = true; _activeExplorer = Application.ActiveExplorer(); _activeExplorer.SelectionChange += new ExplorerEvents_10_SelectionChangeEventHandler(ThisAddIn_SelectionChange); _ribbon1.SetApplication(Application); }
/// <summary> /// Finds all meetings created by our add-in inside Deleted Items and deletes them. /// </summary> private void PurgeMeetingsFromDeletedItems() { Outlook.MAPIFolder deletedItems = Application.ActiveExplorer().Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderDeletedItems); Outlook.Items itemsToPurge = deletedItems.Items; itemsToPurge = itemsToPurge.Restrict(String.Format("[MessageClass] = '{0}'", CUSTOM_MESSAGE_CLASS)); for (int j = itemsToPurge.Count; j >= 1; j--) { AppointmentItem item = itemsToPurge[j] as AppointmentItem; item.Delete(); } }
private void button1_Click(object sender, RibbonControlEventArgs e) { var outlookObj = new Application(); var tmp = outlookObj.CreateItem(OlItemType.olAppointmentItem); MAPIFolder calendar = outlookObj.Session.GetDefaultFolder(OlDefaultFolders.olFolderCalendar); Explorer explorer = outlookObj.ActiveExplorer(); Folder folder = explorer.CurrentFolder as Folder; View view = explorer.CurrentView as View; MailItem mail = view as MailItem; ShowForm(); }
//Selection changed event handling private void CurrentExplorer_Event() { if (Application.ActiveExplorer().Selection.Count <= 0) { return; } object selObject = Application.ActiveExplorer().Selection[1]; if (selObject != null && (selObject is Outlook.MailItem || selObject is Outlook.MeetingItem)) { MainController.SelectionChanged(OutlookItemHelpers.GetItemClass(selObject)); } }
public static bool TryGetSelectedMail(this Application outlook, out MailItem mail) { var explorer = outlook.ActiveExplorer(); if (explorer.Selection.Count > 0) { mail = explorer.Selection[1] as MailItem; return(mail != null); } mail = null; return(false); }
/// <summary> /// Get the CritWatch meetings in a date range. /// </summary> /// <returns></returns> private Outlook.Items GetCritWatchMeetings(DateTime startDate, DateTime endDate) { Outlook.MAPIFolder calendar = Application.ActiveExplorer().Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar); Outlook.Items items = calendar.Items; // filter to just our custom items in our date range string filter = String.Format("[Start] > '{0}' and [End] < '{1}' and [MessageClass] = '{2}'", startDate.ToShortDateString(), endDate.ToShortDateString(), CUSTOM_MESSAGE_CLASS); items = items.Restrict(filter); return(items); }
public static void AddCompareShortcutToShortcutsPane(Application application) { try { Explorer explorer = application.ActiveExplorer(); using (new ComRelease(explorer)) { if (explorer == null) { // not an error this happens when sending via simple mapi return; } Panes panes = explorer.Panes; using (new ComRelease(panes)) { var outlookBar = (_OutlookBarPane) panes["OutlookBar"]; using (new ComRelease(outlookBar)) { OutlookBarGroup outlookBarGroup = outlookBar.CurrentGroup; using (new ComRelease(outlookBarGroup)) { OutlookBarShortcuts outlookBarShortcuts = outlookBarGroup.Shortcuts; if (outlookBarShortcuts == null) { return; } using (new ComRelease(outlookBarShortcuts)) { string linkPath = GetLinkPath(); string targetpath = Path.Combine(OptionApi.GetString("ProgramLocation"), DvExeName); CreateLink(targetpath, linkPath); RemoveUnwantedShortcuts(outlookBarShortcuts); long index = GetShortcutIndex(ShortcutName, outlookBarShortcuts); if (index != -1) { OutlookBarShortcut shortcut = outlookBarShortcuts[index]; using (new ComRelease(shortcut)) { var target = (string) shortcut.Target; if (string.Compare(linkPath, target, true) == 0) { shortcut.SetIcon(GetIconPath()); return; } // Remove the existing shortcut if target is wrong RemoveShortcut(ShortcutName, outlookBarShortcuts); } } // If we got here then either there wasn't a shorcut set up // or the target was not correct for this product if (index > outlookBarShortcuts.Count) { index = outlookBarShortcuts.Count; } else if (index == -1) { index = outlookBarShortcuts.Count + 1; } OutlookBarShortcut newShortcut = outlookBarShortcuts.Add(linkPath, ShortcutName, index); using (new ComRelease(newShortcut)) { newShortcut.SetIcon(GetIconPath()); } } } } } } } catch (Exception ex) { Logger.LogError(ex); } }
public static void RemoveShortcut(Application application) { try { Explorer explorer = application.ActiveExplorer(); using (new ComRelease(explorer)) { if (explorer == null) { // not an error this happens when sending via simple mapi return; } Panes panes = explorer.Panes; using (new ComRelease(panes)) { var outlookBar = (_OutlookBarPane) panes["OutlookBar"]; using (new ComRelease(outlookBar)) { OutlookBarGroup outlookBarGroup = outlookBar.CurrentGroup; using (new ComRelease(outlookBarGroup)) { OutlookBarShortcuts outlookBarShortcuts = outlookBarGroup.Shortcuts; if (outlookBarShortcuts == null) { return; } using (new ComRelease(outlookBarShortcuts)) { RemoveShortcut(ShortcutName, outlookBarShortcuts); } } } } } } catch (Exception e) { Logger.LogError(e); } }
public MailNavigator(Application app, MAPIFolder folder) { this.OutlookApp = app; this.Explorer =app.ActiveExplorer(); this.Folder = folder; if (Explorer.CurrentFolder == folder && Explorer.Selection.Count > 0) { this.Current = new OutlookItem(this.Explorer.Selection[1]); } else { MoveTOStart(); } }