Beispiel #1
0
 private void outlookToolBtn_Click(object sender, EventArgs e)
 {
     DataTable dt = ReadOutlookPstDB();
     if (dt.Rows.Count > 0)
     {
         fsForm = new FolderSelectorForm();
         fsForm.SetCheckedListBox(dt);
         fsForm.SelectFinishedEvent += new SelectFinishedEventHandler(fsForm_SelectFinishedEvent);
         fsForm.ShowDialog();
     }
 }
Beispiel #2
0
        void fsForm_SelectFinishedEvent(object sender, MyEventArgs e)
        {
            fsForm.SelectFinishedEvent -= new SelectFinishedEventHandler(fsForm_SelectFinishedEvent);
            List<string> entries = (List<string>)e.Value;
            Microsoft.Office.Interop.Outlook.Application app = new Microsoft.Office.Interop.Outlook.ApplicationClass();
            Microsoft.Office.Interop.Outlook.NameSpace NS = app.GetNamespace("MAPI");
            Microsoft.Office.Interop.Outlook.MAPIFolder objFolder;
            Microsoft.Office.Interop.Outlook.MailItem objMail;

            DataTable table = new DataTable();
            table.Columns.Add("subject", typeof(string));
            table.Columns.Add("body", typeof(string));
            table.Columns.Add("sentOn", typeof(string));
            try
            {
                foreach (string entryID in entries)
                {
                    objFolder = NS.GetFolderFromID(entryID);
                    for (int i = 1; i <= objFolder.Items.Count; i++)
                    {
                        try
                        {
                            objMail = (Microsoft.Office.Interop.Outlook.MailItem)objFolder.Items[i];
                            DataRow dr = table.NewRow();
                            if (!string.IsNullOrEmpty(objMail.Subject) && !string.IsNullOrEmpty(objMail.HTMLBody))
                            {

                                dr["subject"] = objMail.Subject;
                                dr["body"] = objMail.HTMLBody;
                                dr["sentOn"] = objMail.SentOn.ToString("yyyy-MM-dd HH:mm");
                                table.Rows.Add(dr);
                            }
                        }
                        catch (System.InvalidCastException ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                    }
                }
            }
            catch (COMException ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                NS.Logoff();
                objFolder = null;
                objMail = null;
                app = null;
            }

            origDataTable = table;
            this.toolStripStatusLabel.Text = "从Outlook 2007读取原始邮件成功。";
            this.runToolBtn.Enabled = true;
            this.runToolStripMenuItem.Enabled = true;
            this.fsForm.Close();
            this.fsForm.Dispose();
            this.fsForm = null;
            DataSet ds = new DataSet();
            ds.Tables.Add(origDataTable);
            if (origForm == null)
            {
                origForm = new OrigForm();
                origForm.MdiParent = this;
                origForm.WindowState = FormWindowState.Maximized;
                origForm.FormClosed += new FormClosedEventHandler(origForm_FormClosed);
                origForm.setDataGrigViewContext(ds);
                origForm.Show();
            }
            else
            {
                origForm.setDataGrigViewContext(ds);
                origForm.Activate();
                origForm.WindowState = FormWindowState.Maximized;
                origForm.Focus();
            }
        }