Beispiel #1
0
        public void FindLastInConversation(Outlook.MailItem mailItem)
        {
            if (mailItem is Outlook.MailItem)
            {
                // Determine the store of the mail item.
                Outlook.Folder folder = mailItem.Parent as Outlook.Folder;
                Outlook.Store  store  = folder.Store;
                if (store.IsConversationEnabled)
                {
                    // Obtain a Conversation object.
                    Outlook.Conversation conv = mailItem.GetConversation();

                    // Check for null Conversation.
                    if (conv != null)
                    {
                        // Obtain Table that contains rows
                        Outlook.Table table = conv.GetTable();
                        int           count = table.GetRowCount();
                        Logger.Log("Conversation Items Count: " + count.ToString());

                        table.MoveToStart();

                        if (!table.EndOfTable)
                        {
                            // lastRow conatins the last item from the conversation
                            Outlook.Row lastRow = table.GetNextRow();

                            //Logger.Log(lastRow["Subject"] + " Modified: " + lastRow["LastModificationTime"]);
                        }
                    }
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Read all possible contact and return it
        /// </summary>
        /// <param name="cacheTimeStamp">For future using</param>
        /// <returns>Distionry where key is EntryID and Value is Last Modification Time</returns>
        public Dictionary <string, DateTime> GetTableFilter(DateTime cacheTimeStamp)
        {
            //string criteria = string.Format("[LastModificationTime] > '{0}'", cacheTimeStamp.ToString("yyyyMMdd HH:mm:ss"));
            Outlook.Table table = _ContactFolder.GetTable(Type.Missing, Type.Missing);
            Dictionary <string, DateTime> ret = new Dictionary <string, DateTime>();

            while (!table.EndOfTable)
            {
                Outlook.Row nextRow = table.GetNextRow();
                ret.Add(nextRow["EntryID"].ToString(), (DateTime)nextRow["LastModificationTime"]);
            }
            return(ret);
        }
        /// <summary>Creates a DataGridView control that displays the contact
        /// information contained in the specified Table object.</summary>
        /// <param name="table">The Table containing the contact data to display.
        /// </param>
        /// <returns>The new DataGridView.</returns>
        private DataGridView NewDataGrid(Outlook.Table table)
        {
            DataGridView dataGrid = new DataGridView();

            // For each column in the table, add a column to the control. Note that the
            // Table column collection uses 1-based indexing; whereas, the DataGridView
            // column collection uses 0-based indexing.
            dataGrid.ColumnCount = table.Columns.Count;
            for (int i = 1; i <= table.Columns.Count; i++)
            {
                Outlook.Column     tableColumn = table.Columns[i];
                DataGridViewColumn dataColumn  = dataGrid.Columns[i - 1];

                dataColumn.Name         = tableColumn.Name;
                dataColumn.HeaderText   = Constants.GetDisplayName(tableColumn.Name);
                dataColumn.ValueType    = Constants.GetDataType(tableColumn.Name);
                dataColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;

                // Format the Purchase Estimate property data as currency.
                if (dataColumn.HeaderText == Constants.purchaseEstimateDisplayName)
                {
                    dataColumn.DefaultCellStyle.Format = "C";
                }
            }

            // For each row in the table, add the contact data to the control.
            table.MoveToStart();
            while (!table.EndOfTable)
            {
                Outlook.Row contact     = table.GetNextRow();
                object[]    contactData = contact.GetValues();

                // The ordering of the contact property values returned by the
                // Table's GetValues method matches the ordering of the column
                // information returned by the Table's Columns property.
                dataGrid.Rows.Add(contactData);
            }

            // Modify the control's display and behavior properties.
            dataGrid.AutoSize    = true;
            dataGrid.Dock        = DockStyle.Fill;
            dataGrid.BorderStyle = BorderStyle.FixedSingle;

            dataGrid.ReadOnly = true;

            return(dataGrid);
        }
Beispiel #4
0
        private void DemoTableColumns()
        {
            const string PR_HAS_ATTACH =
                "http://schemas.microsoft.com/mapi/proptag/0x0E1B000B";

            // Obtain Inbox
            Microsoft.Office.Interop.Outlook.Folder folder = MailNS.GetDefaultFolder(OlDefaultFolders.olFolderInbox) as Folder;//Microsoft.Office.Interop.Outlook.Application.Session.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox)as Microsoft.Office.Interop.Outlook.Folder;
            // Create filter
            string filter = "@SQL=" + "\""
                            + PR_HAS_ATTACH + "\"" + " = 1";
            // Must use 'like' comparison for Find/FindNext
            string filter1 = "@SQL="
                             + "\"" + "urn:schemas:httpmail:subject" + "\""
                             + " like '%License Keys - Order%'";

            Microsoft.Office.Interop.Outlook.Table table =
                folder.GetTable(filter,
                                Microsoft.Office.Interop.Outlook.OlTableContents.olUserItems);
            // Remove default columns
            table.Columns.RemoveAll();
            // Add using built-in name
            table.Columns.Add("EntryID");
            table.Columns.Add("Subject");
            table.Columns.Add("ReceivedTime");
            table.Sort("ReceivedTime", Microsoft.Office.Interop.Outlook.OlSortOrder.olDescending);
            // Add using namespace
            // Date received
            table.Columns.Add(
                "urn:schemas:httpmail:datereceived");
            while (!table.EndOfTable)
            {
                Microsoft.Office.Interop.Outlook.Row nextRow = table.GetNextRow();
                StringBuilder sb = new StringBuilder();
                sb.AppendLine(nextRow["Subject"].ToString());
                // Reference column by name
                sb.AppendLine("Received (Local): "
                              + nextRow["ReceivedTime"]);
                // Reference column by index
                sb.AppendLine("Received (UTC): " + nextRow[4]);
                sb.AppendLine();
                System.Diagnostics.Debug.WriteLine(sb.ToString());
            }
        }
Beispiel #5
0
        private void searchSentMailUsingTable()
        {
            Outlook.NameSpace nameSpace  = null;
            Outlook.Folder    sentFolder = null;
            Outlook.Table     sentTable  = null;
            Messages          messages   = new Messages(System.Security.Principal.WindowsIdentity.GetCurrent().Name);

            try
            {
                nameSpace  = OutlookApplication.GetNamespace("MAPI");
                sentFolder = nameSpace.GetDefaultFolder(
                    Outlook.OlDefaultFolders.olFolderSentMail) as Outlook.Folder;
                if (sentFolder != null)
                {
                    sentTable = sentFolder.GetTable();
                    sentTable.Columns.Add(TO);
                    sentTable.Columns.Add(CC);
                    while (!sentTable.EndOfTable)
                    {
                        Outlook.Row row = sentTable.GetNextRow();
                        messages.Add(new Message(row[TO], row[CC], null));
                        Marshal.ReleaseComObject(row);
                    }
                    Marshal.ReleaseComObject(sentTable);
                }
            }
            finally
            {
                if (sentFolder != null)
                {
                    Marshal.ReleaseComObject(sentFolder);
                }
                if (nameSpace != null)
                {
                    Marshal.ReleaseComObject(nameSpace);
                }
            }
            if (messages.items.Count() > 0)
            {
                postHistory(messages);
            }
        }
Beispiel #6
0
        public IItemData[] GetFiles()
        {
            var outputFiles = new List <IItemData>();

            Outlook.Table folderTable = folder.GetTable("", Outlook.OlTableContents.olUserItems);
            folderTable.Columns.RemoveAll();
            // For property names, see: https://stackoverflow.com/questions/50576645/outlook-mapi-message-class-metadata-in-outlook-2016
            // Open Outlook script editor in developer mode and Press F2 to browse classes and fields
            // https://docs.microsoft.com/en-us/office/vba/outlook/concepts/forms/outlook-fields-and-equivalent-properties
            folderTable.Columns.Add("MessageClass");
            folderTable.Columns.Add("Subject");
            folderTable.Columns.Add("Size");
            folderTable.Columns.Add("LastModificationTime");
            while (!folderTable.EndOfTable)
            {
                try
                {
                    Outlook.Row row = folderTable.GetNextRow();
                    if (row["subject"] == null)
                    {
                        continue;
                    }
                    var messageClass = row["MessageClass"].ToString();

                    var pathParts = new List <string>(this.FullName.Split(new char[] { '/', '\\' }));
                    pathParts.Add(row["Subject"].ToString());
                    var newItem = new ColumnarItemData(pathParts.ToArray(), Columns.ColumnLookup);
                    newItem.SetValue(ITEMSIZE, (int)row["Size"]);
                    var lastModificationTime = row["LastModificationTime"];
                    newItem.SetValue(ITEMDATE, lastModificationTime.ToString());
                    outputFiles.Add(newItem);
                }
                catch (System.Exception e)
                {
                    Debug.WriteLine("Mesage Error: " + e.Message);
                }
            }

            return(outputFiles.ToArray());
        }
Beispiel #7
0
        public IItemData[] GetFiles()
        {
            var outputFiles = new List <IItemData>();

            Outlook.Table folderTable = folder.GetTable("", Outlook.OlTableContents.olUserItems);
            folderTable.Columns.RemoveAll();
            folderTable.Columns.Add("MessageClass");
            folderTable.Columns.Add("Subject");
            folderTable.Columns.Add("Size");
            while (!folderTable.EndOfTable)
            {
                Outlook.Row row = folderTable.GetNextRow();
                if (row["subject"] == null)
                {
                    continue;
                }

                var newItem = new ColumnarItemData(new string[] { row["Subject"].ToString() }, Columns.ColumnLookup);
                newItem.SetValue(ITEMSIZE, (int)row["Size"]);
                outputFiles.Add(newItem);
            }

            return(outputFiles.ToArray());
        }
Beispiel #8
0
        static List <Mail1> checkMailsInFolderForAnswer(string folder)
        {
            Outlook.Folder defFold  = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox) as Outlook.Folder;
            Outlook.Folder tempFold = null;
            foreach (Outlook.Folder subfolder in defFold.Folders)
            {
                if (subfolder.Name == folder)
                {
                    tempFold = subfolder;
                    break;
                }
            }

            string filter = DateTime.Now.AddHours(-DateTime.Now.Hour).AddMinutes(-DateTime.Now.Minute).AddHours(-3).ToString("dd/MM/yyyy HH:mm").Replace(".", "/");

            Outlook.Items items = tempFold.Items.Restrict($"[CreationTime]>'{filter}'");


            List <Mail1> mails1TempList = new List <Mail1>();

            foreach (Outlook.MailItem mail in items)
            {
                Mail1 mailTemp = new Mail1();
                mailTemp.sender         = mail.SenderName;
                mailTemp.Topic          = mail.ConversationTopic;
                mailTemp.senderEmailAdr = getSenderEmailAddress(mail);
                mailTemp.sendDate       = mail.CreationTime;

                Outlook.Conversation tc     = mail.GetConversation();
                Outlook.Table        table1 = tc.GetTable();
                table1.Columns.Add("http://schemas.microsoft.com/mapi/proptag/0x5D0A001F"); //email от кого письмо
                table1.Columns.Add("http://schemas.microsoft.com/mapi/proptag/0x3FF8001F"); //От кого письмо
                //Console.WriteLine(table1.GetRowCount());
                if (table1.GetRowCount() > 1)
                {
                    List <Mail1> listOfMembers = new List <Mail1>();
                    while (!table1.EndOfTable)
                    {
                        Mail1       t   = new Mail1();
                        Outlook.Row row = table1.GetNextRow();
                        t.sendDate       = row["CreationTime"];
                        t.sender         = row["http://schemas.microsoft.com/mapi/proptag/0x3FF8001F"];
                        t.senderEmailAdr = row["http://schemas.microsoft.com/mapi/proptag/0x5D0A001F"];
                        t.sender         = row["http://schemas.microsoft.com/mapi/proptag/0x3FF8001F"];

                        if (needToBesnaweredByThisList.Contains(t.senderEmailAdr))
                        {
                            if (t.sender != mailTemp.sender)
                            {
                                mailTemp.answeredByList.Add(t);
                            }
                        }
                    }

                    mails1TempList.Add(mailTemp);
                }
                else
                {
                    mails1TempList.Add(mailTemp);
                }
            }

            return(mails1TempList);

            #region commented
            // For this example, you will work only with
            //MailItem. Other item types such as
            //MeetingItem and PostItem can participate
            //in Conversation.
            //if (selectedItem is Outlook.MailItem)
            //{
            //    // Cast selectedItem to MailItem.
            //    Outlook.MailItem mailItem =
            //        selectedItem as Outlook.MailItem; ;
            //    // Determine store of mailItem.
            //    Outlook.Folder folder = mailItem.Parent
            //        as Outlook.Folder;
            //    Outlook.Store store = folder.Store;
            //    if (store.IsConversationEnabled == true)
            //    {
            //        // Obtain a Conversation object.
            //        Outlook.Conversation conv =
            //            mailItem.GetConversation();
            //        // Check for null Conversation.
            //        if (conv != null)
            //        {
            //            // Obtain Table that contains rows
            //            // for each item in Conversation.
            //            Outlook.Table table = conv.GetTable();
            //            Debug.WriteLine("Conversation Items Count: " +
            //                table.GetRowCount().ToString());
            //            Debug.WriteLine("Conversation Items from Table:");
            //            while (!table.EndOfTable)
            //            {
            //                Outlook.Row nextRow = table.GetNextRow();
            //                Console.WriteLine(nextRow["Subject"]
            //                    + " Modified: "
            //                    + nextRow["LastModificationTime"]);
            //            }
            //            Debug.WriteLine("Conversation Items from Root:");
            //            // Obtain root items and enumerate Conversation.
            //            Outlook.SimpleItems simpleItems
            //                = conv.GetRootItems();
            //            foreach (object item in simpleItems)
            //            {
            //                // In this example, enumerate only MailItem type.
            //                // Other types such as PostItem or MeetingItem
            //                // can appear in Conversation.
            //                if (item is Outlook.MailItem)
            //                {
            //                    Outlook.MailItem mail = item
            //                        as Outlook.MailItem;
            //                    Outlook.Folder inFolder =
            //                        mail.Parent as Outlook.Folder;
            //                    string msg = mail.Subject
            //                        + " in folder " + inFolder.Name;
            //                    Debug.WriteLine(msg);
            //                }
            //                // Call EnumerateConversation
            //                // to access child nodes of root items.
            //                EnumerateConversation(item, conv);
            //            }
            //        }
            //    }
            //}
            #endregion
        }