private void SyncChildProfiles(Outlook.Application oApp, Outlook.Items oItems, Profile profile, bool Prompt) { bool Continue = true; if (profile.ChildProfiles.Count > 0) { if (Prompt) { StringBuilder sb = new StringBuilder(); foreach (Profile ChildProfile in profile.ChildProfiles) { sb.AppendFormat("\t{0}\n", ChildProfile.Title); } Continue = (MessageBox.Show( string.Format("You have selected the '{0}' tag. This tag also contains the following child tags:\n\n{1}\n" + "Do you want to sync the members of these child tags also?", profile.Title, sb.ToString()), "Sync Child Tag Members", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes); } if (Continue) { foreach (Profile ChildProfile in profile.ChildProfiles) { SyncPeople(oApp, oItems, ChildProfile.Title, ChildProfile.Members); SyncChildProfiles(oApp, oItems, ChildProfile, false); } } } }
public List <Email> GetMessages(string entryID, int numPerPage, int pageNum) { List <Email> list = new List <Email>(); Outlook.MAPIFolder f; // if no ID specified, open the inbox if (string.IsNullOrEmpty(entryID)) { f = _nameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox); } else { f = _nameSpace.GetFolderFromID(entryID, ""); } // to handle the sorting, one needs to cache their own instance of the items object Outlook.Items items = f.Items; // sort descending by received time items.Sort("[ReceivedTime]", true); // pull in the correct number of items based on number of items per page and current page number for (int i = (numPerPage * pageNum) + 1; i <= (numPerPage * pageNum) + numPerPage && i <= items.Count; i++) { // ensure it's a mail message Outlook.MailItem mi = (items[i] as Outlook.MailItem); if (mi != null) { list.Add(new Email(mi.EntryID, mi.SenderEmailAddress, mi.SenderName, mi.Subject, mi.ReceivedTime, mi.Size)); } } return(list); }
/// <summary> /// Get recurring appointments in date range. /// </summary> /// <param name="folder"></param> /// <param name="startTime"></param> /// <param name="endTime"></param> /// <returns>Outlook.Items</returns> public static Outlook.Items GetAppointmentsInRange(Outlook.Folder folder, DateTime startTime, DateTime endTime, DateTime lastSync) { string filter = "[Start] >= '" + startTime.ToString("g") + "' AND [End] <= '" + endTime.ToString("g") + "'"; //B08559_CRM_Outlook_sync_bug MGY 2014.03.14 Begin //+ " AND [Sensitivity] <> " + Microsoft.Office.Interop.Outlook.OlSensitivity.olPrivate; //B08559_CRM_Outlook_sync_bug MGY 2014.03.14 End //B12773_CRMOutlookPluginIssues MGY 2016.07.04 Begin //Ez nem működik IncludeRecurrences = true esetén: //+ " AND [LastModificationTime] > '" + lastSync.ToString("g") + "'"; //B12773_CRMOutlookPluginIssues MGY 2016.07.04 End try { Outlook.Items calItems = folder.Items; calItems.IncludeRecurrences = true; calItems.Sort("[Start]", Type.Missing); Outlook.Items restrictItems = calItems.Restrict(filter); if (restrictItems.Count > 0) { return(restrictItems); } else { return(null); } } catch { return(null); } }
private void Archive_Startup(object sender, EventArgs e) { _sentItems = Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMail).Items; _sentItems.ItemAdd += SentItems_ItemAdd; _archiveFolder = Application.Session.DefaultStore.GetRootFolder().Folders[ArchiveFolderName]; }
private void AddInStartUp(object sender, System.EventArgs e) { EmailAddress = this.Application.ActiveExplorer().Session.CurrentUser.AddressEntry.GetExchangeUser().PrimarySmtpAddress; MailAddress address = new MailAddress(EmailAddress); Domain = address.Host; Outlook.MAPIFolder inbox = Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox); mailItems = inbox.Items; mailItems.ItemAdd += new Outlook.ItemsEvents_ItemAddEventHandler(ThreadStarter); }
/// <summary> /// assigns properties to member fields /// </summary> /// <param name="outlookFolder"></param> /// <param name="outlookExplorer"></param> /// <param name="isFolderMappedWithDocLibrary"></param> public UploadBrokenUploads(Outlook.MAPIFolder outlookFolder, Outlook.Explorer outlookExplorer, bool isFolderMappedWithDocLibrary) { try { FolderName = outlookFolder.Name; //Get the details of the folder. Is it is mapped to SP DocLib or SPSIte(Pages) isUserDroppedItemsCanUpload = isFolderMappedWithDocLibrary; addinExplorer = outlookExplorer; activeDroppingFolder = outlookFolder; activeDroppingFolderItems = outlookFolder.Items; } catch (Exception ex) { } }
protected virtual void Dispose(bool isDisposing) { if (isDisposing) { GC.SuppressFinalize(this); } if (_items != null) Marshal.ReleaseComObject(_items); if (_ns != null) Marshal.ReleaseComObject(_ns); if (_sent != null) Marshal.ReleaseComObject(_sent); _ns = null; _sent = null; _items = null; }
public void ApplyFilter(string filter) { if (!string.IsNullOrEmpty(filter)) { Logger.LogInfo("Applying filter " + filter); var items = _sent.Items; _items = items.Restrict(filter); Marshal.ReleaseComObject(items); } else { _items = _sent.Items; } _items.Sort("SentOn", true); }
//Method that runs when the plugin loads private void ThisAddIn_Startup(object sender, System.EventArgs e) { //Prompt to run application, and start and end timer System.Windows.Forms.DialogResult result = System.Windows.Forms.MessageBox.Show("Do you want to run SigX?", "Hit yes, I'll be quick", System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); if (result == DialogResult.Yes) { timer = Stopwatch.StartNew(); ReadMail(); //Start stopwatch and run batch parsing function } //Configure plugin to run when email is added to Inbox outlookNameSpace = this.Application.GetNamespace("MAPI"); inbox = outlookNameSpace.GetDefaultFolder( Microsoft.Office.Interop.Outlook. OlDefaultFolders.olFolderInbox); items = inbox.Items; items.ItemAdd += new Outlook.ItemsEvents_ItemAddEventHandler(ReadSingleMail); // Modified method to run for single email }
public void LoadOutlookContacts() { Outlook.MAPIFolder contactsFolder = _outlookNamespace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts); _outlookContacts = contactsFolder.Items; //FilterOutlookContactDuplicates(); }
/// <summary> /// Implements the OnStartupComplete method of the IDTExtensibility2 interface. /// Receives notification that the host application has completed loading. /// </summary> /// <param term='custom'> /// Array of parameters that are host application specific. /// </param> /// <seealso class='IDTExtensibility2' /> public void OnStartupComplete(ref System.Array custom) { try { // Get the ContactsFolder Object Config.CheckShowConfig(); NameSpace nspace = myApplicationObject.GetNamespace("MAPI"); ContactsFolder = nspace.GetDefaultFolder(OlDefaultFolders.olFolderContacts); // Register for It``emAdd Event // Note: if more then 16 Items are added, the event doesn't come. items = ContactsFolder.Items; logger.Debug("Setting ItemAdd Event"); items.ItemAdd += new Microsoft.Office.Interop.Outlook.ItemsEvents_ItemAddEventHandler(Items_ItemAdd); logger.Debug("Setting ItemChange Event"); items.ItemChange += new Microsoft.Office.Interop.Outlook.ItemsEvents_ItemChangeEventHandler(Items_ItemChange); logger.Debug("Setting ItemRemove Event"); items.ItemRemove += new Microsoft.Office.Interop.Outlook.ItemsEvents_ItemRemoveEventHandler(Items_ItemRemove); RefreshContacts(); } catch (System.Exception ex) { logger.Error(ex.Message); logger.Debug(ex.StackTrace.ToString()); MessageBox.Show(ex.Message); } }
/// <summary> /// Constructor /// </summary> /// <param name="outlookItems">Outlook items</param> public MailItems(Outlook.Items outlookItems) { _mailItems = outlookItems; }
public IOfficeConnectAddin(ThisAddIn addin) { try { _addin = addin; IOfficeConnectGlobals.ErEnUkendtBrugerAktiv = true; var outlookInboxFolder = _addin.Application.Session.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox); // Get outlook inbox store ID IOfficeConnectGlobals.InboxFolderEntryID = outlookInboxFolder.EntryID; IOfficeConnectGlobals.UserStoreID = outlookInboxFolder.StoreID; Task.Run(() => { IOfficeConnectGlobals.EnsureCache(); log.Info("Cache was built"); }); var brugerKendt = IOfficeConnectGlobals.GetCurrentBruger(); if (brugerKendt == null) { var m = string.Format("Brugeren du er logget på windows med ({0}) er ukendt i IOffice", Environment.UserName); log.Warn(m); MessageBox.Show(m, "Ukendt bruger", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { log.InfoFormat("Bruger med ID {0} og navn {1} logget ind", brugerKendt.ID, brugerKendt.Navn); IOfficeConnectGlobals.ErEnUkendtBrugerAktiv = false; if (IOfficeConnectGlobals.ArchiveRootFolderExists(_addin.Application.Session, brugerKendt) == true) { // Hookup on mail received _addin.Application.NewMailEx += Application_NewMailEx; // Hookup item sent // http://stackoverflow.com/questions/23803960/outlook-itemadd-event-not-triggered _sentItemsFolder = _addin.Application.Session.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderSentMail); _sentItems = _sentItemsFolder.Items; _sentItems.ItemAdd -= sentItems_ItemAdd; _sentItems.ItemAdd += sentItems_ItemAdd; log.Info("Events new mail og itemsend hooked up"); IOfficeConnectGlobals.ErFuldtInitialiseret = true; } else { var m = string.Format("Mappen til arkivering kunne ikke findes\r\nGå venligst ind i IOffice og vælg Settings\r\nUnder settings vælg fanebladet References\r\nTryk på luppen og vælg mappen \"Kunder\" under offentlige mapper\r\n\r\nGenstart Outlook når mappen er valgt så IOffice connect kan anvende indstillingen"); MessageBox.Show(m, "Mappen ikke fundet", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } } catch (Exception e) { var m = string.Format("Generel fejl under opstart: {0}", e.Message); log.Error(m, e); MessageBox.Show(m, "Ukendt fejl under opstart", MessageBoxButtons.OK, MessageBoxIcon.Warning); throw; } }
/// <summary> /// Initializes the OutLook application and retrieves the meetings scheduled for current day. /// For logging into OutLook, we need the profile name. Default profile name is extracted from registry settings. /// </summary> private void InitializeMeetingDuration() { try { if (!Process.GetProcessesByName("OUTLOOK").Any()) return; outlookApplication = Marshal.GetActiveObject("Outlook.Application") as Outlook.Application; nameSpace = outlookApplication.GetNamespace("mapi"); var profile = Registry.GetValue(@"HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles", "DefaultProfile", null); nameSpace.Logon(profile.ToString(), Missing.Value, true, true); fldCalander = nameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar) as Outlook.Folder; fldDeletedItems = nameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderDeletedItems) as Outlook.Folder; items = GetAppointmentsInRange(fldCalander); fldCalander.BeforeItemMove += fldCalander_BeforeItemMove; items.ItemAdd += Items_ItemAdd; items.ItemChange += Items_ItemChange; if (items != null) { foreach (Outlook.AppointmentItem oAppt in items) { meetings.Add(oAppt.GlobalAppointmentID, new MeetingDetails(oAppt.Start, oAppt.End, oAppt.Duration)); } } } catch (Exception ex) { log.Error(ex.ToString()); } }
/// <summary> /// <c>MAPIFolderWrapper</c> member function /// assigns properties to member fields and register add event on <c> Outlook.Items</c> /// </summary> /// <param name="outlookFolder"></param> /// <param name="outlookExplorer"></param> /// <param name="isFolderMappedWithDocLibrary"></param> public MAPIFolderWrapper(ref Outlook.MAPIFolder outlookFolder, Outlook.Explorer outlookExplorer, bool isFolderMappedWithDocLibrary) { try { FolderName = outlookFolder.Name; //Get the details of the folder. Is it is mapped to SP DocLib or SPSIte(Pages) isUserDroppedItemsCanUpload = isFolderMappedWithDocLibrary; addinExplorer = outlookExplorer; activeDroppingFolder = outlookFolder; activeDroppingFolderItems = outlookFolder.Items; activeDroppingFolderItems.ItemAdd -= new Microsoft.Office.Interop.Outlook.ItemsEvents_ItemAddEventHandler(activeDroppingFolderItems_ItemAdd); //bw.DoWork += delegate(object sender, DoWorkEventArgs e) { bw_DoWork(sender, e, Item); }; } catch (Exception ex) { } activeDroppingFolderItems.ItemAdd += new Microsoft.Office.Interop.Outlook.ItemsEvents_ItemAddEventHandler(activeDroppingFolderItems_ItemAdd); }
public bool logon(string sProfile, string sUser, string sPassword, bool bShowDialog) { bool bRet = false; bool bNewSession = true; _userData.sUser = sUser; try { MailNS.Logon(sProfile, sPassword, bShowDialog, bNewSession); MyInbox = MailNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox); OnStateChanged(new StatusEventArgs(StatusType.ews_started, "logon done")); getMailsAsync(); MyItems = MyInbox.Items; MyItems.ItemAdd += new Outlook.ItemsEvents_ItemAddEventHandler(newItem); bRet = true; } catch (System.Exception ex) { System.Diagnostics.Debug.WriteLine("Exception: " + ex.Message); } return bRet; }
public IOfficeConnectAddin(ThisAddIn addin) { try { _addin = addin; IOfficeConnectGlobals.ErEnUkendtBrugerAktiv = true; var outlookInboxFolder = _addin.Application.Session.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox); // Get outlook inbox store ID IOfficeConnectGlobals.InboxFolderEntryID = outlookInboxFolder.EntryID; IOfficeConnectGlobals.UserStoreID = outlookInboxFolder.StoreID; Task.Run(() => { IOfficeConnectGlobals.EnsureCache(); log.Info("Cache was built"); }); var brugerKendt = IOfficeConnectGlobals.GetCurrentBruger(); if (brugerKendt == null) { var m = string.Format("Brugeren du er logget på windows med ({0}) er ukendt i IOffice", Environment.UserName); log.Warn(m); MessageBox.Show(m, "Ukendt bruger", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { log.InfoFormat("Bruger med ID {0} og navn {1} logget ind", brugerKendt.ID, brugerKendt.Navn); IOfficeConnectGlobals.ErEnUkendtBrugerAktiv = false; // Hookup on mail received _addin.Application.NewMailEx += Application_NewMailEx; // Hookup item sent // http://stackoverflow.com/questions/23803960/outlook-itemadd-event-not-triggered _sentItemsFolder = _addin.Application.Session.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderSentMail); _sentItems = _sentItemsFolder.Items; _sentItems.ItemAdd -= sentItems_ItemAdd; _sentItems.ItemAdd += sentItems_ItemAdd; log.Info("Events new mail og itemsend hooked up"); } } catch (Exception e) { var m = string.Format("Generel fejl under opstart: {0}", e.Message); log.Error(m, e); MessageBox.Show(m, "Ukendt fejl under opstart", MessageBoxButtons.OK, MessageBoxIcon.Warning); throw; } }
private void ThisAddIn_Startup(object sender, EventArgs e) { //Executive flag addin _outlookNameSpace = Application.GetNamespace("MAPI"); _inbox = _outlookNameSpace.GetDefaultFolder( Outlook.OlDefaultFolders.olFolderInbox); //Generate contacts from email I have received from capSpire _contacts = _outlookNameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts); _items = _inbox.Items; _items.ItemAdd += items_ItemAdd; AddContactsToItems(); _selectExplorers = Application.Explorers; _selectExplorers.NewExplorer += newExplorer_Event; AddToolbar(); }
private void handleAutotrain(Boolean register) { if (register) { if (this.folder_spam != null) { this.items_spam = this.folder_spam.Items; this.items_spam.ItemAdd += new Outlook.ItemsEvents_ItemAddEventHandler(onNewItem_Spam); } if (this.folder_ham != null) { this.items_ham = this.folder_ham.Items; this.items_ham.ItemAdd += new Outlook.ItemsEvents_ItemAddEventHandler(onNewItem_Ham); } } else { if (this.items_spam != null) { this.items_spam.ItemAdd -= new Outlook.ItemsEvents_ItemAddEventHandler(onNewItem_Spam); this.items_spam = null; } if (this.items_ham != null) { this.items_ham.ItemAdd -= new Outlook.ItemsEvents_ItemAddEventHandler(onNewItem_Ham); this.items_ham = null; } } }
private void HookupSentMail() { if (SentItems != null) { SentItems.ItemAdd -= new ItemsEvents_ItemAddEventHandler(Items_ItemAdd); } SentItems = GetDefaultNamespace().GetDefaultFolder(OlDefaultFolders.olFolderSentMail).Items; SentItems.ItemAdd += new ItemsEvents_ItemAddEventHandler(Items_ItemAdd); }
void ThisAddIn_BeforeFolderSwitch(object NewFolder, ref bool Cancel) { var folder = NewFolder as Folder; if (lstFolderIds.Contains(folder.EntryID)) return; lstFolderIds.Add(folder.EntryID); _items = folder.Items; _items.ItemRemove += Items_ItemRemove; }
private void ThisAddInStartup(object sender, EventArgs e) { const string SOURCE = CLASS_NAME + "Startup"; try { Stopwatch swStartUpTime = new Stopwatch(); swStartUpTime.Start(); Logger.Init(); var version = Application.Version; AppVersion = Convert.ToInt32(version.Split(new[] { '.' })[0]); Logger.Info(SOURCE, string.Format("{0}Assembly version: {1}{0}Install path: {2}{0}" + "OS: {3} ({4}){0}Outlook version: {5} {6}{0}Profile: {9}{0}Framework version: {7}{0}IE version: {8}", Environment.NewLine, Assembly.GetExecutingAssembly().FullName, Utils.GetRootPath(), Environment.OSVersion, Environment.Is64BitOperatingSystem ? "x64" : "x86", version, Environment.Is64BitProcess ? "64-bit" : "", RuntimeEnvironment.GetSystemVersion(), Utils.GetBrowserVersion(), Session.CurrentProfileName)); //read the stored settings first var gotStored = GetStoredSettings(); //add new mail handler Application.NewMailEx += ApplicationNewMailEx; _inspWrappers = new Dictionary<string, InspWrap>(); _explWrappers = new Dictionary<string, ExplWrap>(); Inspectors = Application.Inspectors; #region Commented below code as it takes more time to make Outlook ready if we have more mails in selected folder (Inbox) Explorers = Application.Explorers; _items = Application.ActiveExplorer().CurrentFolder.Items; lstFolderIds.Add(Application.ActiveExplorer().CurrentFolder.EntryID); _items.ItemRemove += Items_ItemRemove; Application.ActiveExplorer().BeforeFolderSwitch += ThisAddIn_BeforeFolderSwitch; if (Explorers.Count > 0) { //may not be an ActiveExplorer on restart after a crash Explorer active; try { active = Application.ActiveExplorer(); } catch { active = null; } if (active == null) { Logger.Info(SOURCE, "no ActiveExplorer"); } else { AddWrapper(Application.ActiveExplorer()); } } #endregion //finish initialization in background, so we can exit startup immediately ThreadPool.QueueUserWorkItem(InitHandler, gotStored); ////load the current accounts //ValidateAccountsRdo(); //Logger.Verbose(SOURCE, string.Format( // "found {0} accounts", Accounts.Count)); ////read the stored settings //GetStoredSettings(); //Logger.Verbose(SOURCE, string.Format( // "active accounts: {0}", // ListCurrentAccounts())); //EvalAttachmentPreview(); ////CheckRegistrations(); Logger.Info(SOURCE, string.Format("Takes {0} seconds", swStartUpTime.Elapsed.TotalSeconds)); } catch (Exception ex) { Logger.Error(SOURCE, ex.ToString()); } }
private void ThisAddIn_Startup(object sender, System.EventArgs e) { RemoveMenubar(); AddMenuBar(); outlookNamespace = this.Application.GetNamespace("MAPI"); inbox = outlookNamespace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox); outlookItems = inbox.Items; outlookItems.ItemAdd += new Outlook.ItemsEvents_ItemAddEventHandler(items_ItemAdd); }
public OutlookDataSource(IHostApplicationProvider hostAppProvider, IMail mailItem) { _mailItem = mailItem; Logger.LogInfo("OutlookSentItemSource.OutlookDataSource()"); _ns = hostAppProvider.Host.GetNamespace("MAPI"); _sent = _ns.GetDefaultFolder(MsOutlook.OlDefaultFolders.olFolderSentMail); _items = _sent.Items; }