public void Dispose() { UnBindEvents(); #if (COMRELEASE) System.Runtime.InteropServices.Marshal.ReleaseComObject(inspector); #endif inspector = null; item.Dispose(); item = null; }
private void btnRun_Click(object sender, EventArgs e) { //Load PST file Spire.Email.Outlook.OutlookFile olf = new OutlookFile(@"..\..\..\..\..\..\Data\Sample.pst"); //Load Outlook MSG file OutlookItem item = new OutlookItem(); item.LoadFromFile(@"..\..\..\..\..\..\Data\Sample.msg"); //Select the "Inbox" folder OutlookFolder inboxFolder = olf.RootOutlookFolder.GetSubFolder("Inbox"); //Add the MSG to "Inbox" folder inboxFolder.AddItem(item); MessageBox.Show("Completed"); }
private void Application_ItemSend(object Item, ref bool Cancel) { var item = new OutlookItem(Item); if (!item.IsSupportedItem) { // non-supported item, for now ... return; } if (item.DeferredDeliveryTime != s_outlookMagicDateTimeNotDefinedConst) { // already deferred, don't get involve return; } DateTime deferredDeliveryTime = GetNextAllowedTime(); if (deferredDeliveryTime <= DateTime.Now) { // we are in the allowed time return; } DialogResult result = MessageBox.Show($"It's off work time, defer this item to {deferredDeliveryTime}?", "Work-life Balance Guard", MessageBoxButtons.YesNoCancel);//, , button, icon); switch (result) { case DialogResult.Yes: item.DeferredDeliveryTime = deferredDeliveryTime; break; case DialogResult.No: // do nothing break; case DialogResult.Cancel: Cancel = true; break; } }
/// <summary> /// Event handler for the new inspector event /// </summary> /// <param name="inspector"></param> void _Inspectors_NewInspector(Outlook.Inspector inspector) { try { OutlookItem objOutlookItem = new OutlookItem(inspector.CurrentItem); // Make sure this is a message item if ((objOutlookItem.Class == Outlook.OlObjectClass.olMail) && (objOutlookItem.MessageClass.StartsWith(Constants.IPMClass))) { // Check to see if this is a new window we don't already track MessageInspector objExistingInspector = this.FindMessageInspector(inspector); // If not found in our dictionary, add it if (objExistingInspector == null) { MessageInspector objMessageInspector = new MessageInspector(inspector); objMessageInspector.OnClose += new EventHandler <CloseEventArgs>(objMessageInspector_OnClose); objMessageInspector.OnInvalidateControl += ObjMessageInspector_OnInvalidateControl; _MessageInspectorDictionary.Add(objMessageInspector.Id, objMessageInspector); //Customize the UI //Office.CommandBars objCommandBars = objMessageInspector.Window.CommandBars; } } } catch (Exception Ex) { System.Diagnostics.Trace.WriteLine(Ex); MessageBox.Show( Ex.Message, Constants.EditorAppName, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private ConversationDTO GetRelatedItems(OutlookItem sourceItem, bool latestFirst, bool currentFolderOnly = true) { Conversation c = ((dynamic)sourceItem.InnerObject).GetConversation(); ConversationDTO dto = new ConversationDTO() { Topic = sourceItem.ConversationTopic }; var table = c.GetTable(); if (table.GetRowCount() == 0) { dto.Items = new List<OutlookItem> { sourceItem }; dto.FirstRootItem = sourceItem; } else { table.MoveToStart(); var row = table.GetNextRow(); var item = new OutlookItem(table.Session.GetItemFromID(row["EntryID"])); dto.FirstRootItem = item; SortedDictionary<DateTime, OutlookItem> ordered = new SortedDictionary<DateTime, OutlookItem>(); while (true) { if (!ordered.Values.Any(i => i.EntryID == item.EntryID) && (!currentFolderOnly || item.Parent.Name.Equals(Folder.Name, StringComparison.OrdinalIgnoreCase))) { DateTime sfield = item.TryGetPropertyValue("ReceivedTime", out sfield) ? sfield : item.LastModificationTime; ordered.Add(sfield, item); } if (table.EndOfTable) break; row = table.GetNextRow(); item = new OutlookItem(table.Session.GetItemFromID(row["EntryID"])); } var list = ordered.Values.ToList(); if (latestFirst) list.Reverse(); dto.Items = list; } return dto; }
protected virtual OutlookItem SetSelected(OutlookItem item) { /* * this needs to be worked upon. * The problem is that although the item gets selected internally, yet it doesn't show up the same in the listview. */ if (Explorer.CurrentFolder == Folder) { try { if (Explorer.Selection.Count > 0) { var oldItem = this.Explorer.Selection[1]; this.Explorer.RemoveFromSelection(oldItem); } this.Explorer.AddToSelection(item.InnerObject); } catch (System.Exception ex) { // we can tolerate selection errors - they are bound to occur e.g. in conversation view. //if (!ex.Message.Contains("invalid for a conversation view")) // System.Windows.Forms.MessageBox.Show(string.Format("Oops, an error occured: {0}\n{1}", ex.Message, Messages.CONTACT)); } } this.Current = item; return item; }
public virtual OutlookItem PreviousConversationItem() { var items = AllItems; string currentCID; if (items[items.Count].EntryID != Current.EntryID) { if (!Current.TryGetPropertyValue("ConversationID", out currentCID)) return Previous(); int i; for (i = items.Count; i >= 1; i--) { if (items[i].EntryID == Current.EntryID) { break; } } int itemLen = items.Count; for (i++; i <= itemLen; i++) { string thisCID; var item = new OutlookItem(items[i]); if (item.TryGetPropertyValue("ConversationID", out thisCID) && currentCID == thisCID) { continue; } return SetSelected(item); } } return null; }
public virtual OutlookItem NextConversationItem() { var items = AllItems; string currentCID; // items are ordered in order from last to first. if (items[1].EntryID != Current.EntryID) { // if the current item is not a part of any conversation, then regular next would occur. if (!Current.TryGetPropertyValue("ConversationID", out currentCID)) return Next(); int i; for (i = items.Count; i >= 1; i--) { if (items[i].EntryID == Current.EntryID) { break; } } for (i--; i >= 1; i--) { string thisCID; var item = new OutlookItem(items[i]); if (item.TryGetPropertyValue("ConversationID", out thisCID) && currentCID == thisCID) { continue; } return SetSelected(item); } } return null; }
public OutlookInspector(RlOutlook.Inspector inspector) { this.inspector = inspector; this.item = OutlookItem.CreateItem(inspector.CurrentItem); BindEvents(); }
private void GetOtherHeaders(OutlookItem item, out string smallHead, string[] exclusions) { StringBuilder header = new StringBuilder(); if (!exclusions.Contains("title", StringComparer.OrdinalIgnoreCase)) { header.Append("<p>"); AppendTitle(item.InnerObject, header, false); } AddAttachments(header, item.Attachments); if (!exclusions.Contains("title", StringComparer.OrdinalIgnoreCase)) header.Append("</p>"); smallHead = header.ToString(); }
private string GetItemHtmlForConversation(OutlookItem item) { string header, body; GetItemContent(item, out header, out body, new string[] { "title", "by" }); string wrapStart = item.EntryID != mNavigator.Current.EntryID ? "<div>" : "<div role='region' aria-labelledby='mCurrent'><span id='mCurrent' style='display:none;'>Currently selected mail</span>"; return string.Format("{4}<h2 onclick=\"{0}\">{1}</h2><br/>{2}</div><br/><br/>{3}", GetTogglingJS(), ((dynamic) item.InnerObject).SenderName, header, body, wrapStart); }
private void GetItemContent(OutlookItem item, out string header, out string body, string[] exclusions = null) { exclusions = exclusions ?? new string[0]; switch (item.Class) { case OlObjectClass.olMail: GetMailHeaders((MailItem)item.InnerObject, out header, exclusions); body = ((MailItem)item.InnerObject).HTMLBody; break; case OlObjectClass.olMeetingRequest: case OlObjectClass.olMeetingCancellation: case OlObjectClass.olMeetingResponseNegative: case OlObjectClass.olMeetingResponsePositive: case OlObjectClass.olMeetingResponseTentative: case OlObjectClass.olMeetingForwardNotification: GetMeetingHeaders((MeetingItem)item.InnerObject, out header, exclusions); body = item.Body; break; default: GetOtherHeaders(item, out header, exclusions); body = item.Body; break; } }
private void CMAttachment_ItemClicked(object sender, ToolStripItemClickedEventArgs e) { try { dynamic obj = CMAttachment.Tag; int index = (int)obj.Index; Attachment attachment; if (InConversationView) { using (var item = new OutlookItem(mNavigator.OutlookApp.Session.GetItemFromID(obj.ID))) { attachment = item.Attachments[index]; } } else { attachment = mNavigator.Current.Attachments[index]; } switch (e.ClickedItem.Name) { case "CMAOpen": var tempFilePath = GetTempFilePath(attachment.FileName); attachment.SaveAsFile(tempFilePath); System.Diagnostics.Process.Start(tempFilePath); break; case "CMASave": saveFileDialog1.FileName = attachment.FileName; if (saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK) attachment.SaveAsFile(saveFileDialog1.FileName); break; case "CMASaveAndOpen": saveFileDialog1.FileName = attachment.FileName; if (saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK) { attachment.SaveAsFile(saveFileDialog1.FileName); System.Diagnostics.Process.Start(saveFileDialog1.FileName); } break; } System.Runtime.InteropServices.Marshal.ReleaseComObject(attachment); } catch (System.Exception ex) { ExceptionHandler.Catch(ex); } }
public override void RemoveSynchronisationProperties() { OutlookItem.ClearSynchronisationProperties(); }
// OnMyButtonClick routine handles all button click events // and displays IRibbonControl.Context in message box public void OnMyButtonClick(Office.IRibbonControl control) { string msg = string.Empty; if (control.Context is Outlook.AttachmentSelection) { msg = "Context=AttachmentSelection" + "\n"; Outlook.AttachmentSelection attachSel = control.Context as Outlook.AttachmentSelection; foreach (Outlook.Attachment attach in attachSel) { msg = msg + attach.DisplayName + "\n"; } } else if (control.Context is Outlook.Folder) { msg = "Context=Folder" + "\n"; Outlook.Folder folder = control.Context as Outlook.Folder; msg = msg + folder.Name; } else if (control.Context is Outlook.Selection) { msg = "Context=Selection" + "\n"; Outlook.Selection selection = control.Context as Outlook.Selection; if (selection.Count == 1) { OutlookItem olItem = new OutlookItem(selection[1]); msg = msg + olItem.Subject + "\n" + olItem.LastModificationTime; } else { msg = msg + "Multiple Selection Count=" + selection.Count; } } else if (control.Context is Outlook.OutlookBarShortcut) { msg = "Context=OutlookBarShortcut" + "\n"; Outlook.OutlookBarShortcut shortcut = control.Context as Outlook.OutlookBarShortcut; msg = msg + shortcut.Name; } else if (control.Context is Outlook.Store) { msg = "Context=Store" + "\n"; Outlook.Store store = control.Context as Outlook.Store; msg = msg + store.DisplayName; } else if (control.Context is Outlook.View) { msg = "Context=View" + "\n"; Outlook.View view = control.Context as Outlook.View; msg = msg + view.Name; } else if (control.Context is Outlook.Inspector) { msg = "Context=Inspector" + "\n"; Outlook.Inspector insp = control.Context as Outlook.Inspector; if (insp.AttachmentSelection.Count >= 1) { Outlook.AttachmentSelection attachSel = insp.AttachmentSelection; foreach (Outlook.Attachment attach in attachSel) { msg = msg + attach.DisplayName + "\n"; } } else { OutlookItem olItem = new OutlookItem(insp.CurrentItem); msg = msg + olItem.Subject; } } else if (control.Context is Outlook.Explorer) { msg = "Context=Explorer" + "\n"; Outlook.Explorer explorer = control.Context as Outlook.Explorer; if (explorer.AttachmentSelection.Count >= 1) { Outlook.AttachmentSelection attachSel = explorer.AttachmentSelection; foreach (Outlook.Attachment attach in attachSel) { msg = msg + attach.DisplayName + "\n"; } } else { Outlook.Selection selection = explorer.Selection; if (selection.Count == 1) { OutlookItem olItem = new OutlookItem(selection[1]); msg = msg + olItem.Subject + "\n" + olItem.LastModificationTime; } else { msg = msg + "Multiple Selection Count=" + selection.Count; } } } else if (control.Context is Outlook.NavigationGroup) { msg = "Context=NavigationGroup" + "\n"; Outlook.NavigationGroup navGroup = control.Context as Outlook.NavigationGroup; msg = msg + navGroup.Name; } else if (control.Context is Microsoft.Office.Core.IMsoContactCard) { msg = "Context=IMsoContactCard" + "\n"; Office.IMsoContactCard card = control.Context as Office.IMsoContactCard; if (card.AddressType == Office.MsoContactCardAddressType. msoContactCardAddressTypeOutlook) { // IMSOContactCard.Address is AddressEntry.ID Outlook.AddressEntry addr = Globals.ThisAddIn.Application.Session.GetAddressEntryFromID( card.Address); if (addr != null) { msg = msg + addr.Name; } } } else if (control.Context is Outlook.NavigationModule) { msg = "Context=NavigationModule"; } else if (control.Context == null) { msg = "Context=Null"; } else { msg = "Context=Unknown"; } MessageBox.Show(msg, "RibbonXOutlook14AddinCS", MessageBoxButtons.OK, MessageBoxIcon.Information); }
private static Status DownloadMeetingsForDate(DateTime date, Microsoft.Office.Interop.Outlook.MAPIFolder calendarFolder) { Status status = new Status(date); string strDate1 = date.Date.ToString(@"MMMM dd, yyyy hh:mm tt"); string strDate2 = date.Date.AddDays(1).ToString(@"MMMM dd, yyyy hh:mm tt"); Microsoft.Office.Interop.Outlook.AppointmentItem item = null; //Single Appt for any recurring apointment Microsoft.Office.Interop.Outlook.AppointmentItem singleAppt = null; //string sFilter = "[Start] >= '" + strDate1 + "'" // + " and " + // "[End] <= '" + strDate2 + "'"; //string sFilter = "([Start] >= '" + // date.Date.ToString("g") // + "' AND [End] <= '" + // date.AddDays(1).Date.ToString("g") + "'"; //appointments that start and end within the time string sFilter1 = "[Start] >= '" + date.Date.ToString("g") + "' AND [End] <= '" + date.AddDays(1).Date.ToString("g") + "'"; //appointments that start before starttime and end after starttime string sFilter2 = "[Start] < '" + date.Date.ToString("g") + "' AND [End] > '" + date.Date.ToString("g") + "'"; //appointments that start before endtime and end after endtime string sFilter3 = "[Start] < '" + date.AddDays(1).ToString("g") + "' AND [End] > '" + date.AddDays(1).Date.ToString("g") + "'"; string sFilter = ("( " + sFilter1 + " ) OR ( " + sFilter2 + " ) OR ( " + sFilter3 + " )"); calendarFolder.Items.IncludeRecurrences = true; Microsoft.Office.Interop.Outlook.Items outlookCalendarItems = calendarFolder.Items.Restrict(sFilter); outlookCalendarItems.Sort("[Start]", Type.Missing); Debug.WriteLine("Count after Restrict: {0}", outlookCalendarItems.Count); foreach (var v in outlookCalendarItems) { try { //This Appointment item = (Microsoft.Office.Interop.Outlook.AppointmentItem)v; if (item.IsRecurring) { try { DateTime startDateTime = item.StartInStartTimeZone; Microsoft.Office.Interop.Outlook.RecurrencePattern pattern = item.GetRecurrencePattern(); singleAppt = pattern.GetOccurrence(date.Date.Add(startDateTime.TimeOfDay)) as Microsoft.Office.Interop.Outlook.AppointmentItem; if (singleAppt == null) { continue; } else { System.Runtime.InteropServices.Marshal.FinalReleaseComObject(item); item = null; item = singleAppt; } } catch { continue; } } var subject = item.Subject; var body = item.Body; var start = item.StartInStartTimeZone; var end = item.EndInEndTimeZone; var location = item.Location; var organizer = item.Organizer; OutlookItem c = new OutlookItem(); c.Subject = "From " + start.ToString("t") + " To " + end.ToString("t"); if (c.Subject == "From 12:00 AM To 12:00 AM") c.Subject = "All Day"; c.Name = item.Subject; if (!string.IsNullOrWhiteSpace(location)) c.MessageBody = "Location : " + location + Environment.NewLine; c.MessageBody += "Organized by " + organizer + Environment.NewLine + body; c.MessageHTMLBody = c.MessageBody; c.DisplayTime = start.ToString("t"); if (c.DisplayTime == "12:00 AM") c.DisplayTime = " "; //empty string, no point is displaying 12:00 AM Debug.WriteLine(c.Name); Debug.WriteLine(c.Subject); Debug.WriteLine(c.MessageBody); status.ListOfItems.Add(c); } catch { continue; } finally { if (item != null) { System.Runtime.InteropServices.Marshal.FinalReleaseComObject(item); item = null; } if (singleAppt != null) { System.Runtime.InteropServices.Marshal.FinalReleaseComObject(singleAppt); singleAppt = null; } } } return status; }
private static Status DownloadStatusForDate(DateTime date, Microsoft.Office.Interop.Outlook.MAPIFolder objMAPIFolder) { Status status = new Status(date); string strDate1 = date.Date.ToString(@"MMMM dd, yyyy hh:mm tt"); string strDate2 = date.Date.AddDays(1).ToString(@"MMMM dd, yyyy hh:mm tt"); Microsoft.Office.Interop.Outlook.MailItem item = null; string sFilter = "[SentOn] >= '" + strDate1 + "'" + " and " + "[SentOn] <= '" + strDate2 + "'"; Microsoft.Office.Interop.Outlook.Items restrictedFolder = objMAPIFolder.Items.Restrict(sFilter); Debug.WriteLine("Count after Restrict: {0}", restrictedFolder.Count); foreach (var v in restrictedFolder) { try { item = (Microsoft.Office.Interop.Outlook.MailItem)v; var subject = item.Subject.ToLower(); var body = item.Body.ToLower(); if (subject.Contains("work") || subject.Contains("standup") || subject.Contains("stand up") || subject.Contains("wfh") || subject.Contains("pto") || subject.Contains("sick") || subject.Contains("home") || subject.Contains("leaving") || subject.Contains("today") || subject.Contains("scrum") || subject.Contains("late") //|| body.Contains("standup") //|| body.Contains("stand up") //|| body.Contains("wfh") //|| body.Contains("pto") //|| body.Contains("sick") //|| body.Contains("home") //|| body.Contains("leaving") ) { Debug.WriteLine("Sent: {0} {1} {2}", item.SentOn.ToLongDateString(), item.SenderName, item.Subject); OutlookItem c = new OutlookItem(); c.MessageBody = item.Body; c.MessageHTMLBody = item.HTMLBody; c.Subject = item.Subject; c.Name = item.SenderName; c.DisplayTime = item.SentOn.ToString("t"); status.ListOfItems.Add(c); } } catch { continue; } finally { if (item != null) { System.Runtime.InteropServices.Marshal.FinalReleaseComObject(item); item = null; } } } return status; }
public OutlookData LoadData() { XmlDocument doc = new XmlDocument(); string path = Path.Combine(env.WebRootPath, "data", "data.xml"); doc.Load(path); List <OutlookItem> outlist = new List <OutlookItem>(); List <OutlookItem> outlist1 = new List <OutlookItem>(); XmlNodeList list = doc.DocumentElement.SelectNodes("/root/Customers"); int count = list.Count - 7; int index = 0; foreach (XmlNode node1 in list) { if (count != -1 && index >= count) { OutlookItem txt1 = new OutlookItem(); txt1.ContactID = node1.SelectSingleNode("ContactID").InnerText; txt1.CompanyName = node1.SelectSingleNode("CompanyName").InnerText; txt1.ContactName = node1.SelectSingleNode("ContactName").InnerText; txt1.ContactTitle = node1.SelectSingleNode("ContactTitle").InnerText; txt1.Greetings = node1.SelectSingleNode("Greetings").InnerText; txt1.Message = node1.SelectSingleNode("Message").InnerText; txt1.To = node1.SelectSingleNode("To").InnerText; txt1.Address = node1.SelectSingleNode("Address").InnerText; txt1.City = node1.SelectSingleNode("City").InnerText; txt1.PostalCode = node1.SelectSingleNode("PostalCode").InnerText; txt1.Today = node1.SelectSingleNode("Today").InnerText; txt1.Time = node1.SelectSingleNode("Time").InnerText; txt1.Date = node1.SelectSingleNode("Date").InnerText; txt1.Day = node1.SelectSingleNode("Day").InnerText; txt1.Size = node1.SelectSingleNode("Size").InnerText; outlist1.Add(txt1); } if (index != 3 && index != 4 && index != 5 && index != 6 && index != 7 && index != 8 && index != 9 && index != 10) { OutlookItem txt = new OutlookItem(); txt.ContactID = node1.SelectSingleNode("ContactID").InnerText; txt.CompanyName = node1.SelectSingleNode("CompanyName").InnerText; txt.ContactName = node1.SelectSingleNode("ContactName").InnerText; txt.ContactTitle = node1.SelectSingleNode("ContactTitle").InnerText; txt.Greetings = node1.SelectSingleNode("Greetings").InnerText; txt.Message = node1.SelectSingleNode("Message").InnerText; txt.To = node1.SelectSingleNode("To").InnerText; txt.Address = node1.SelectSingleNode("Address").InnerText; txt.City = node1.SelectSingleNode("City").InnerText; txt.PostalCode = node1.SelectSingleNode("PostalCode").InnerText; txt.Today = node1.SelectSingleNode("Today").InnerText; txt.Time = node1.SelectSingleNode("Time").InnerText; txt.Date = node1.SelectSingleNode("Date").InnerText; txt.Day = node1.SelectSingleNode("Day").InnerText; txt.Size = node1.SelectSingleNode("Size").InnerText; outlist.Add(txt); } index++; } TreeViewInfo data = new TreeViewInfo { TreeData = treeData() }; MenuInfo data1 = new MenuInfo { MenuData = menuData() }; return(new OutlookData { OutlookItem = outlist, OutlookItem1 = outlist1, TreeviewDB = data, MenuDB = data1 }); }