Exemplo n.º 1
0
        public List <string> loadmailmoi()
        {
            List <string> luunoidungmaimoi = new List <string>();

            // send and recevie mail
            Outlook._Application app     = new Outlook.Application();
            Outlook._NameSpace   nsp     = app.GetNamespace("MAPI");
            Outlook.MAPIFolder   inbox85 = nsp.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
            nsp.SendAndReceive(true);
            try
            {
                foreach (Object item in inbox85.Items)
                {
                    if (item is Outlook.MailItem)
                    {
                        Outlook.MailItem mi = (Outlook.MailItem)item;
                        if (mi != null && mi.UnRead == true)
                        {
                            luunoidungmaimoi.Add("Người gửi: " + mi.SenderEmailAddress + " - Nội dung: " + mi.Subject + " - Ngày: " + mi.SentOn.ToShortDateString() + " - Giờ: " + mi.SentOn.ToShortTimeString());
                        }
                    }
                }
                return(luunoidungmaimoi);
            }
            catch (Exception e)
            {
                ghiloi.WriteLogError(e);
                return(null);
            }
        }
Exemplo n.º 2
0
        public bool AtualizarMailItem(string categories, string entryId)
        {
            bool ret = false;

            try
            {
                Outlook.Application myApp         = new Outlook.Application();
                Outlook._NameSpace  mapiNameSpace = myApp.GetNamespace("MAPI");

                Outlook.MAPIFolder fd = mapiNameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);

                string storeId = fd.StoreID;

                Outlook.MailItem mailItem = mapiNameSpace.GetItemFromID(entryId, storeId) as Outlook.MailItem;

                mailItem.Categories = categories;
                mailItem.Close(Outlook.OlInspectorClose.olSave);

                myApp.Quit();

                ret = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(ret);
        }
Exemplo n.º 3
0
        private void RECEIVEbutton_Click(object sender, EventArgs e)
        {
            try
            {
                outlook._Application _app  = new outlook.Application();
                outlook._NameSpace   _ns   = _app.GetNamespace("MAPI");
                outlook.MAPIFolder   inbox = _ns.GetDefaultFolder(outlook.OlDefaultFolders.olFolderInbox);
                _ns.SendAndReceive(true);
                dt = new DataTable("inbox");
                dt.Columns.Add("Subject", typeof(string));
                dt.Columns.Add("Sender", typeof(string));
                dt.Columns.Add("Body", typeof(string));
                dt.Columns.Add("Date", typeof(string));

                dataGrid.DataSource = dt;
                foreach (outlook.MailItem item in inbox.Items)
                {
                    dt.Rows.Add(new object[] { item.Subject, item.SenderName, item.HTMLBody, item.SentOn.ToLongDateString() + "" + item.SentOn.ToLongTimeString() });
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "message", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void receiveMails()
        {
            try
            {
                Outlook._Application _app  = new Outlook.Application();
                Outlook._NameSpace   _ns   = _app.GetNamespace("MAPI");
                Outlook.MAPIFolder   inbox = _ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
                _ns.SendAndReceive(true);

                dt = new DataTable("Inbox");
                dt.Columns.Add("Date", typeof(string));
                dt.Columns.Add("Sender Name", typeof(string));
                dt.Columns.Add("Sender Email", typeof(string));
                dt.Columns.Add("Subject", typeof(string));
                dt.Columns.Add("Body", typeof(string));
                bunifuCustomDataGrid1.DataSource = dt;

                foreach (Outlook.MailItem item in inbox.Items)
                {
                    dt.Rows.Add(new object[] { item.SentOn.ToLongDateString() + " " + item.SentOn.ToLongTimeString(), item.SenderName, item.SenderEmailAddress, item.Subject, item.HTMLBody });
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 5
0
        public MainForm()
        {
            if (Environment.GetCommandLineArgs().Contains("-auto"))
            {
                AutoMode = true;
            }

            InitializeComponent();
            if (AutoMode)
            {
                this.Hide();
                this.SuspendLayout();
            }

            foreach (string tag in Columns)
            {
                EntryTable.Columns.Add(tag);
            }

            dataGridView1.DataSource = EntryTable;

            objNS = objOutlook.Session;

            if (AutoMode)
            {
                getContactData();
                updateTable();
                this.Dispose();
                this.Close();
                Environment.Exit(0);
            }
        }
Exemplo n.º 6
0
        public void Carregar()
        {
            try
            {
                if (cboProjeto.Items.Count > 0)
                {
                    cboProjeto.SelectedItem = cboProjeto.Items[0];
                }

                Microsoft.Office.Interop.Outlook.MAPIFolder  inboxFolder = null;
                Microsoft.Office.Interop.Outlook.Application app         = null;
                Microsoft.Office.Interop.Outlook._NameSpace  ns          = null;
                Microsoft.Office.Interop.Outlook.MailItem    item        = null;

                app = new Microsoft.Office.Interop.Outlook.Application();
                ns  = app.GetNamespace("MAPI");
                ns.Logon(null, null, false, false);
                inboxFolder = ns.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);

                for (int i = 1; i <= inboxFolder.Items.Count; i++)
                {
                    item = (Microsoft.Office.Interop.Outlook.MailItem)inboxFolder.Items[i];
                    dgvInbox.Rows.Add(item.ToString(), item.SenderName, item.Subject, item.LastModificationTime.ToShortDateString(), item.Body.Replace("\r\n\r\n", "\r\n"));
                }

                this.ShowDialog();
            }
            catch (System.Exception ex)
            {
                WinControls.ApresentarErro(AssistErroException.TratarErro(ex));
            }
        }
Exemplo n.º 7
0
 private void OutlookClient(string foldername)
 {
     Outlook._Application _app       = new Outlook.Application();
     Outlook._NameSpace   _ns        = _app.GetNamespace("MAPI");
     Outlook.MAPIFolder   Inbox      = _ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
     Outlook.Items        items      = Inbox.Items;
     Outlook.MAPIFolder   userfolder = Inbox.Folders[foldername];
 }
Exemplo n.º 8
0
        public MonitorPath()
        {
            this.m_OutlookApp       = new Microsoft.Office.Interop.Outlook.Application();
            this.m_OutlookNameSpace = (Microsoft.Office.Interop.Outlook._NameSpace) this.m_OutlookApp.GetNamespace("MAPI");
            this.m_MAPIFolder       = this.m_OutlookNameSpace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
            this.m_Explorer         = this.m_MAPIFolder.GetExplorer(false);
            this.m_OutlookNameSpace.Logon(System.Reflection.Missing.Value, System.Reflection.Missing.Value, false, true);

            this.m_PageQueue         = new Queue <System.Windows.Controls.UserControl>();
            this.m_MonitorPageWindow = new MonitorPageWindow();
        }
Exemplo n.º 9
0
        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            // Define the Old Menu Bar
            PacktOldMenuBar = this.Application.ActiveExplorer().CommandBars.ActiveMenuBar;
            // Define the new Menu Bar into the existing menu bar
            PacktNewMenuBar = (Office.CommandBarPopup)PacktOldMenuBar.Controls.Add(Office.MsoControlType.msoControlPopup, missing, missing, missing, false);
            //If PacktNewMenuBar not found then the code will add it
            if (PacktNewMenuBar != null)
            {
                // Set caption for the Menu
                PacktNewMenuBar.Caption = "Analyze PKCS#7 structure";
                // Tag string value passing
                PacktNewMenuBar.Tag = strMenuString;
                // Assigning button type
                PacktButton1 = (Office.CommandBarButton)PacktNewMenuBar.Controls.Add(Office.MsoControlType.msoControlButton, missing, missing, 1, true);
                // Setting up the button style
                PacktButton1.Style = Office.MsoButtonStyle.msoButtonIconAndCaptionBelow;
                // Set button caption
                PacktButton1.Caption = "Analyze PKCS#7 structure";
                // Set the menu visible
                PacktNewMenuBar.Visible = true;
            }



            // Verify the PacktCustomToolBar exist and add to the application
            if (PacktCustomToolBar == null)
            {
                // Adding the commandbar to Active explorer
                Office.CommandBars PacktBars = this.Application.ActiveExplorer().CommandBars;
                // Adding PacktCustomToolBar to the commandbars
                PacktCustomToolBar = PacktBars.Add("NewPacktToolBar", Office.MsoBarPosition.msoBarTop, false, true);
            }
            // Adding button to the custom tool bar
            Office.CommandBarButton MyButton1 = (Office.CommandBarButton)PacktCustomToolBar.Controls.Add(1, missing, missing, missing, missing);
            // Set the button style
            MyButton1.Style = Office.MsoButtonStyle.msoButtonCaption;
            // Set the caption and tag string
            MyButton1.Caption = "Analyze PKCS#7 structure";
            MyButton1.Tag     = "Analyze PKCS#7 structure";
            if (this.PacktButtonA == null)
            {
                // Adding the event handler for the button in the toolbar
                this.PacktButtonA   = MyButton1;
                PacktButtonA.Click += new Office._CommandBarButtonEvents_ClickEventHandler(ButtonClick);
            }
            olApp = new Outlook.ApplicationClass();
            Outlook._NameSpace olNs = olApp.GetNamespace("MAPI");

            olExplorer = olApp.ActiveExplorer();
            //  olExplorer.SelectionChange += new Outlook.ExplorerEvents_10_SelectionChangeEventHandler(CurrentExplorer_Event);
        }
		public OutlookMail()
		{
			//http://www.c-sharpcorner.com/uploadfile/casperboekhoudt/sendingemailsthroughoutlook12052005000124am/sendingemailsthroughoutlook.aspx

			oApp = new Outlook.Application();
			oNameSpace = oApp.GetNamespace("MAPI");
			oNameSpace.Logon(null, null, true, true);

			//Calender: Outlook.OlDefaultFolders.olFolderCalendar 
			//Contacts: Outlook.OlDefaultFolders.olFolderContacts 
			//Inbox: Outlook.OlDefaultFolders.olFolderInbox 

			oOutboxFolder = oNameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderOutbox);
		}
Exemplo n.º 11
0
        private void InitializeVariables()
        {
            app = new Outlook.Application();

            ns = app.GetNamespace("MAPI");

            inboxFolder = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);

            items = inboxFolder.Items;

            //  Add event handler when new mail arrives in Inbox
            items.ItemAdd +=
                new Outlook.ItemsEvents_ItemAddEventHandler(Items_AddItem);
        }
Exemplo n.º 12
0
        public OutlookMail()
        {
            //http://www.c-sharpcorner.com/uploadfile/casperboekhoudt/sendingemailsthroughoutlook12052005000124am/sendingemailsthroughoutlook.aspx

            oApp       = new Outlook.Application();
            oNameSpace = oApp.GetNamespace("MAPI");
            oNameSpace.Logon(null, null, true, true);

            //Calender: Outlook.OlDefaultFolders.olFolderCalendar
            //Contacts: Outlook.OlDefaultFolders.olFolderContacts
            //Inbox: Outlook.OlDefaultFolders.olFolderInbox

            oOutboxFolder = oNameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderOutbox);
        }
Exemplo n.º 13
0
        protected void Recieve_Email_Click(object sender, EventArgs e)
        {
            try
            {
                Outlook._Application _app  = new Outlook.Application();
                Outlook._NameSpace   _ns   = _app.GetNamespace("MAPI");
                Outlook.MAPIFolder   inbox = _ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
                _ns.SendAndReceive(true);

                DataTable dt = InitializeDataTable();

                string from1 = from.Text;
                string to1   = to.Text;

                DateTime dtFr =
                    DateTime.ParseExact(from1, "MM/dd/yyyy", CultureInfo.InvariantCulture);
                DateTime dtTo =
                    DateTime.ParseExact(to1, "MM/dd/yyyy", CultureInfo.InvariantCulture);
                int count = 0;
                foreach (Outlook.MailItem item in inbox.Items)
                {
                    if (dtFr <= item.SentOn && item.SentOn < dtTo.AddDays(1))
                    {
                        count++;
                        dt.Rows.Add(new object[] { count,
                                                   item.SentOn.ToLongDateString() + " " + item.SentOn.ToLongTimeString(),
                                                   item.SenderEmailAddress,
                                                   item.Subject,
                                                   item.SenderName,
                                                   item.Body });
                    }
                }

                dataGrid.DataSource = dt;
                dataGrid.DataBind();
            }
            catch (Exception ex)
            {
                ScriptManager.RegisterClientScriptBlock(
                    this,
                    typeof(Page),
                    "TScript",
                    "alert('There is an error when reading email!')",
                    true);
            }
        }
Exemplo n.º 14
0
        public MonitorPath()
        {
            this.m_OutlookApp = new Microsoft.Office.Interop.Outlook.Application();
            this.m_OutlookNameSpace = (Microsoft.Office.Interop.Outlook._NameSpace)this.m_OutlookApp.GetNamespace("MAPI");
            this.m_MAPIFolder = this.m_OutlookNameSpace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
            this.m_Explorer = this.m_MAPIFolder.GetExplorer(false);
            this.m_OutlookNameSpace.Logon(System.Reflection.Missing.Value, System.Reflection.Missing.Value, false, true);

            this.m_LastReportDistributionHeartBeat = DateTime.Now.AddMinutes(-5);

            ISubscriber subscriber = Business.RedisConnection.Instance.GetSubscriber();
            subscriber.Subscribe("ReportDistributionHeartBeat", (channel, message) =>
            {
                this.m_LastReportDistributionHeartBeat = DateTime.Now;
            });

            this.m_PageQueue = new Queue<System.Windows.Controls.UserControl>();
            this.m_MonitorPageWindow = new MonitorPageWindow();
        }
Exemplo n.º 15
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                Outlook._Application _app       = new Outlook.Application();
                Outlook._NameSpace   _ns        = _app.GetNamespace("MAPI");
                Outlook.MAPIFolder   Inbox      = _ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
                Outlook.Items        items      = Inbox.Items;
                Outlook.MAPIFolder   userfolder = Inbox.Folders["AutomateFolder"];
                Outlook.MAPIFolder   moveto     = Inbox.Folders["AutomateProcessed"];
                _ns.SendAndReceive(true);


                dt = new DataTable("workBox");
                dt.Columns.Add("From", typeof(string));
                dt.Columns.Add("To", typeof(string));
                dt.Columns.Add("Subject", typeof(string));
                dataGridView1.DataSource = dt;

                foreach (Outlook.MailItem item in userfolder.Items)
                {
                    dt.Rows.Add(new object[]
                    {
                        item.SenderName, item.To, item.Subject
                    });
                    if (item.SenderName.Contains("Bryan"))
                    {
                        MessageBox.Show("Match process based on table rules: " +
                                        item.SenderName);
                        item.Move(moveto);
                    }
                }
            }

            catch (Exception ex)
            {
                MessageBox.Show("OL-ERROR: " + ex.Message);
            }

            //MessageBox.Show("testing");
        }
Exemplo n.º 16
0
        private void deleteAppointment()
        {
            DateTime currDateTime = DateTime.Now.Date;

            outlook.AppointmentItem selectedItem = new outlook.AppointmentItem();
            MainWindow.main.monApp_listbox.SelectedItem.ToString();



            outlook._Application app        = new outlook.Application();
            outlook._NameSpace   ns         = app.GetNamespace("MAPI");
            outlook.MAPIFolder   mAPIFolder = ns.GetDefaultFolder(outlook.OlDefaultFolders.olFolderCalendar);

            foreach (outlook.AppointmentItem item in mAPIFolder.Items)
            {
                if (item.Equals(selectedItem))
                {
                    item.Delete();
                }
            }
        }
Exemplo n.º 17
0
        private List <JournalEntry> GetJournalEntries()
        {
            List <JournalEntry> entries = new List <JournalEntry>();

            Outlook.Application o  = new Outlook.Application();
            Outlook._NameSpace  ns = (Outlook._NameSpace)o.GetNamespace("MAPI");
            Outlook.MAPIFolder  f  = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderJournal);

            foreach (var item in f.Items)
            {
                Outlook.JournalItem journal = item as Outlook.JournalItem;
                if (journal != null)
                {
                    entries.Add(new JournalEntry()
                    {
                        Betreff = journal.Subject, BeginntAm = journal.CreationTime, Dauer = journal.Duration, Text = journal.Body, Kategorien = journal.Categories
                    });
                }
            }
            return(entries);
        }
Exemplo n.º 18
0
 public void deleteBySubjectKeywords(string subj)
 {
     try
     {
         _ns   = _app.GetNamespace("MAPI");
         inbox = _ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
         _ns.SendAndReceive(true);
         foreach (Outlook.MailItem item in inbox.Items)
         {
             if (item.Subject.Contains(subj))
             {
                 Console.WriteLine("Subject : " + item.Subject + "from : " + item.SenderName + "is deleted");
                 item.Delete();
             }
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
 }
Exemplo n.º 19
0
        public void outLookApp_NewMailEx(string entryIdCollection)
        {
            try
            {
                Outlook.Application application = new Outlook.Application();
                Outlook._NameSpace  nameSpace   = application.GetNamespace("MAPI");

                var              configuration  = ConfigurationManager.AppSettings;
                var              stopWordsText  = configuration["stopList"];
                string[]         stopWordsArray = stopWordsText.Split(',');
                Outlook.MailItem item           = nameSpace.GetItemFromID(entryIdCollection);
                if (item != null)
                {
                    if (item.MessageClass == "IPM.Note")
                    {
                        foreach (var filter in stopWordsArray)
                        {
                            if (!string.IsNullOrEmpty(item.Subject))
                            {
                                if (item.Subject.ToUpper().Contains(filter.ToUpper()))
                                {
                                    ShowMessage(@"Urgent mail recived");
                                    break;
                                }
                            }
                            if (item.Importance == Outlook.OlImportance.olImportanceHigh)
                            {
                                ShowMessage(@"Urgent mail recived");
                                break;
                            }
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                ShowMessage(ex.Message);
            }
        }
Exemplo n.º 20
0
        public static void ReadOutlook()
        {
            Outlook._Application olApp = new Outlook.ApplicationClass();
            Outlook._NameSpace   olNS  = olApp.GetNamespace("MAPI");
            olNS.Logon("@OutlookEmail", "@OutlookPassword", false, false);
            Outlook.MAPIFolder oFolder = olNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);

            TodayDate = DateTime.Now.ToString("MM/dd/yyyy");
            Outlook.Items oItems = oFolder.Items.Restrict("[ReceivedTime] >= '" + TodayDate + "'");
            //Outlook.Items oItems = oFolder.Items.Restrict("[UnRead] = true");

            for (int i = 1; i <= oItems.Count; i++)
            {
                Microsoft.Office.Interop.Outlook.MailItem oMsg = (Microsoft.Office.Interop.Outlook.MailItem)oItems[i];
                MailSubject = oMsg.Subject.ToString();
                MailBody    = System.Web.HttpUtility.JavaScriptStringEncode(oMsg.Body);

                if (MailSubject.StartsWith("RE:") || MailSubject.StartsWith("FW:") || MailSubject.StartsWith("Re:") || MailSubject.StartsWith("Fw:") || MailSubject.StartsWith("Fwd:"))
                {
                    // Do not fetch mail with contains word above (reply and forward type)
                }
                else
                {
                    EmailCount++;
                    NewEmailList.Add(MailSubject);
                    Console.WriteLine(MailSubject + MailBody);
                    CreatJiraIssue(MailSubject, MailBody);
                }
            }
            ListName = string.Join("\n", NewEmailList.ToArray());
            Console.WriteLine(EmailCount);
            Microsoft.Office.Interop.Outlook.MailItem oMsgSend = (Outlook.MailItem)olApp.CreateItem(Outlook.OlItemType.olMailItem);
            oMsgSend.To      = "######Recieved_Email######";
            oMsgSend.To      = "######Sender_Email######";
            oMsgSend.Subject = "Summary Auto Email Fetching " + TodayDate;
            oMsgSend.Body    = "All New Email count: " + EmailCount + "\n\nFetching complete: " + EmailCount + "\n\nList Email names: \n\n" + ListName;
            oMsgSend.Save();
            oMsgSend.Send();
        }
Exemplo n.º 21
0
        public void ReadFromOutlook()
        {   
            Microsoft.Office.Interop.Outlook.PostItem item = null;

            Dictionary<string, EmailDataModel> senderContribuition = new Dictionary<string, EmailDataModel>();

            string department = String.Empty;
            string geo = String.Empty;
            string name = string.Empty;
            string individualImage = String.Empty;

            try
            {
                app = new Microsoft.Office.Interop.Outlook.Application();
                ns = app.GetNamespace("MAPI");
                ns.Logon(null, null, false, false);
                LoggerClass.WriteException(DateTime.Now, "Namespace", ns.ToString());
            }
            catch (System.Exception ex)
            {
                LoggerClass.WriteException(DateTime.Now, "Logic", ex.Message);
            }
        }
Exemplo n.º 22
0
 public void showUnReadMail()
 {
     try
     {
         _ns   = _app.GetNamespace("MAPI");
         inbox = _ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
         _ns.SendAndReceive(true);
         foreach (Outlook.MailItem item in inbox.Items)
         {
             if (item.UnRead == true)
             {
                 Console.WriteLine("Subject : " + item.Subject);
                 Console.WriteLine("Sender Name : " + item.SenderName);
                 Console.WriteLine("Body : " + item.HTMLBody);
                 Console.WriteLine("Data : " + item.SentOn.ToLongDateString() + " " + item.SentOn.ToLongTimeString());
             }
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
 }
Exemplo n.º 23
0
        /*
         * create map key:createTime-----value:System.__ComObject
         *
         * StartTime EndTime Subject filter all send items
         *
         */
        public SortedDictionary <DateTime, string> ItemMapInfo(DateTime startDate, DateTime endDate, string subjectString)
        {
            string tempPath = System.IO.Path.GetTempPath();

            //try delete before files
            try
            {
                string[] htmlList = Directory.GetFiles(tempPath, "*.html");
                foreach (string f in htmlList)
                {
                    File.Delete(f);
                }
            }
            catch (DirectoryNotFoundException ex)
            {
                MessageBox.Show(ex.ToString());
            }

            if (string.IsNullOrEmpty(subjectString))
            {
                return(null);
            }
            if (string.IsNullOrEmpty(this.startDate.ToString()))
            {
                return(null);
            }

            if (string.IsNullOrEmpty(this.endDate.ToString()))
            {
                return(null);
            }


            //Store emails filter by start & end time
            //SortedDictionary<DateTime, object> tempdic2 = new SortedDictionary<DateTime, object>();

            app = new Microsoft.Office.Interop.Outlook.Application();
            ns  = app.GetNamespace("MAPI");
            ns.Logon("emailadress", "pwd", false, false);

            //Get all sent items list
            sendEmailItems = ns.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderSentMail).Items;

            //Count No. of sent items.
            //richTextBox1.AppendText("\n"+"Total send items = " + sendEmailItems.Count);

            try
            {
                int countNum = 1;

                foreach (var mail in sendEmailItems)
                {
                    Microsoft.Office.Interop.Outlook.MailItem ml = mail as Microsoft.Office.Interop.Outlook.MailItem;
                    //Filter needed  mail by subject in all mails

                    if (ml != null)
                    {
                        if (ml.Subject != null)
                        {
                            if (ml.Subject.ToUpper().Contains(subjectString.ToUpper()))
                            {
                                if (DateTime.Compare(ml.CreationTime, startDate) > 0 && DateTime.Compare(ml.CreationTime, endDate) < 0)
                                {
                                    string mailTempPath = System.IO.Path.Combine(tempPath, countNum + ".html");

                                    ml.SaveAs(mailTempPath, OlSaveAsType.olHTML);
                                    tempdic.Add(ml.CreationTime, ml.HTMLBody);

                                    countNum++;
                                }
                            }
                        }
                    }
                }
                if (tempdic.Count() == 0)
                {
                    MessageBox.Show("Please check your selection for subject/time/sendmailbox");
                }

                //Filter needed mail by starttime and endtime in all emails(sorted by time)
                tempdic.OrderBy(KeyValuePair => KeyValuePair.Key);
            }
            catch (ObjectDisposedException ex)
            {
                MessageBox.Show(ex.ToString());
            }
            finally
            {
                ns  = null;
                app = null;
            }

            return(tempdic);
        }
Exemplo n.º 24
0
        private void btnGetEmails_Click(object sender, EventArgs e)
        {
            //Initialize the Outlook Application Object to its name spaces and Inbox folder and Resticts its action to read the Unread Mails alone.
            Outlook._Application _app         = new Outlook.Application();
            Outlook._NameSpace   _ns          = _app.GetNamespace("MAPI");
            Outlook.MAPIFolder   inbox        = _ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
            Outlook.Items        unReadEmails = inbox.Items.Restrict("[Unread]=true");

            //Show the progress of connection
            _ns.SendAndReceive(false);

            // Variable to initialise the Index to 1st Mail
            var index = 1;


            //Loop through Each mail in the Inbox
            foreach (Outlook.MailItem item in unReadEmails)
            {
                //Object for Email attachments
                var attachments = new List <EmailAttachment>();

                if (item.Attachments.Count > 0)
                {
                    //Loop Through Each Mail to get Attachments
                    for (int i = 1; i <= item.Attachments.Count; i++)
                    {
                        //Filter attached files
                        var attachment = new EmailAttachment
                        {
                            FileName    = item.Attachments[i].FileName,
                            DisplayName = item.Attachments[i].DisplayName,
                            Size        = item.Attachments[i].Size,
                            PathName    = item.Attachments[i].PathName
                        };

                        // Temp location of the downloaded Attachments
                        var tempFile = @"c:\temp\" + attachment.FileName;
                        item.Attachments[i].SaveAsFile(tempFile);

                        //Read attachments on downlod completion
                        attachment.Attachments = File.ReadAllBytes(tempFile);
                        //Remove Temp Files
                        File.Delete(tempFile);
                        //Attchment Assigned to Model Object
                        attachments.Add(attachment);
                    }
                }

                //Assign the MailModel attributes
                newEmails.Add(new EMailModel
                {
                    EMailSequenceNumber = index++,
                    Subject             = item.Subject,
                    Body               = item.Body,
                    Date               = item.SentOn,
                    SenderName         = item.SenderName,
                    SenderEmailAddress = item.SenderEmailAddress,
                    Attachment         = attachments
                });
            }

            //Displays the Mail records in the GridView
            gvDisplayEmails.DataSource = newEmails;
        }
Exemplo n.º 25
0
 public List<MAPIFolder> SearchSelectedFolders(List<string> folderNames)
 {
     List<MAPIFolder> searchFolders = new List<MAPIFolder>();
     app = new Microsoft.Office.Interop.Outlook.Application();
     ns = app.GetNamespace("MAPI");
     foreach (MAPIFolder searchFolder in ns.Folders)
     {
         foreach (MAPIFolder sub in searchFolder.Folders)
         {
             if (folderNames.Contains(sub.FolderPath))
             {
                 searchFolders.Add(sub);
             }
         }
     }
     return searchFolders;
 }
Exemplo n.º 26
0
        public void getAllAppointmentsForCurrentWeek()
        {
            DateTime currDateTime = DateTime.Now.Date;

            outlook._Application app        = new outlook.Application();
            outlook._NameSpace   ns         = app.GetNamespace("MAPI");
            outlook.MAPIFolder   mAPIFolder = ns.GetDefaultFolder(outlook.OlDefaultFolders.olFolderCalendar);

            //add items into lists and listbox elements
            foreach (outlook.AppointmentItem item in mAPIFolder.Items)
            {
                if (item.Start.Day == currDateTime.Day)
                {
                    if (item.Start.DayOfWeek.ToString() == "Monday")
                    {
                        MainWindow.main.monList.Add(item);
                        if (MainWindow.main.monApp_listbox.Items.Count < 2)
                        {
                            MainWindow.main.monApp_listbox.Items.Add(item.Subject + "  : " + item.Start.TimeOfDay.ToString());
                        }
                    }
                    else if (item.Start.DayOfWeek.ToString() == "Tuesday")
                    {
                        MainWindow.main.tueList.Add(item);
                        if (MainWindow.main.tueApp_listbox.Items.Count < 2)
                        {
                            MainWindow.main.tueApp_listbox.Items.Add(item.Subject + "  : " + item.Start.TimeOfDay.ToString());
                        }
                    }
                    else if (item.Start.DayOfWeek.ToString() == "Wednesday")
                    {
                        MainWindow.main.wedList.Add(item);
                        if (MainWindow.main.wedApp_listbox.Items.Count < 2)
                        {
                            MainWindow.main.wedApp_listbox.Items.Add(item.Subject + "  : " + item.Start.TimeOfDay.ToString());
                        }
                    }
                    else if (item.Start.DayOfWeek.ToString() == "Thursday")
                    {
                        MainWindow.main.thuList.Add(item);
                        if (MainWindow.main.thuApp_listbox.Items.Count < 2)
                        {
                            MainWindow.main.thuApp_listbox.Items.Add(item.Subject + "  : " + item.Start.TimeOfDay.ToString());
                        }
                    }
                    else if (item.Start.DayOfWeek.ToString() == "Friday")
                    {
                        MainWindow.main.friList.Add(item);
                        if (MainWindow.main.friApp_listbox.Items.Count < 2)
                        {
                            MainWindow.main.friApp_listbox.Items.Add(item.Subject + "  : " + item.Start.TimeOfDay.ToString());
                        }
                    }
                    else if (item.Start.DayOfWeek.ToString() == "Saturday")
                    {
                        MainWindow.main.satList.Add(item);
                        if (MainWindow.main.satApp_listbox.Items.Count < 2)
                        {
                            MainWindow.main.satApp_listbox.Items.Add(item.Subject + "  : " + item.Start.TimeOfDay.ToString());
                        }
                    }
                    else if (item.Start.DayOfWeek.ToString() == "Sunday")
                    {
                        MainWindow.main.sunList.Add(item);
                        if (MainWindow.main.sunApp_listbox.Items.Count < 2)
                        {
                            MainWindow.main.sunApp_listbox.Items.Add(item.Subject + "  : " + item.Start.TimeOfDay.ToString());
                        }
                    }
                }
                else if (item.Start.Day == currDateTime.AddDays(1).Day)
                {
                    if (item.Start.DayOfWeek.ToString() == "Monday")
                    {
                        MainWindow.main.monList.Add(item);
                        if (MainWindow.main.monApp_listbox.Items.Count < 2)
                        {
                            MainWindow.main.monApp_listbox.Items.Add(item.Subject + "  : " + item.Start.TimeOfDay.ToString());
                        }
                    }
                    else if (item.Start.DayOfWeek.ToString() == "Tuesday")
                    {
                        MainWindow.main.tueList.Add(item);
                        if (MainWindow.main.tueApp_listbox.Items.Count < 2)
                        {
                            MainWindow.main.tueApp_listbox.Items.Add(item.Subject + "  : " + item.Start.TimeOfDay.ToString());
                        }
                    }
                    else if (item.Start.DayOfWeek.ToString() == "Wednesday")
                    {
                        MainWindow.main.wedList.Add(item);
                        if (MainWindow.main.wedApp_listbox.Items.Count < 2)
                        {
                            MainWindow.main.wedApp_listbox.Items.Add(item.Subject + "  : " + item.Start.TimeOfDay.ToString());
                        }
                    }
                    else if (item.Start.DayOfWeek.ToString() == "Thursday")
                    {
                        MainWindow.main.thuList.Add(item);
                        if (MainWindow.main.thuApp_listbox.Items.Count < 2)
                        {
                            MainWindow.main.thuApp_listbox.Items.Add(item.Subject + "  : " + item.Start.TimeOfDay.ToString());
                        }
                    }
                    else if (item.Start.DayOfWeek.ToString() == "Friday")
                    {
                        MainWindow.main.friList.Add(item);
                        if (MainWindow.main.friApp_listbox.Items.Count < 2)
                        {
                            MainWindow.main.friApp_listbox.Items.Add(item.Subject + "  : " + item.Start.TimeOfDay.ToString());
                        }
                    }
                    else if (item.Start.DayOfWeek.ToString() == "Saturday")
                    {
                        MainWindow.main.satList.Add(item);
                        if (MainWindow.main.satApp_listbox.Items.Count < 2)
                        {
                            MainWindow.main.satApp_listbox.Items.Add(item.Subject + "  : " + item.Start.TimeOfDay.ToString());
                        }
                    }
                    else if (item.Start.DayOfWeek.ToString() == "Sunday")
                    {
                        MainWindow.main.sunList.Add(item);
                        if (MainWindow.main.sunApp_listbox.Items.Count < 2)
                        {
                            MainWindow.main.sunApp_listbox.Items.Add(item.Subject + "  : " + item.Start.TimeOfDay.ToString());
                        }
                    }
                }
                else if (item.Start.Day == currDateTime.AddDays(2).Day)
                {
                    if (item.Start.DayOfWeek.ToString() == "Monday")
                    {
                        MainWindow.main.monList.Add(item);
                        if (MainWindow.main.monApp_listbox.Items.Count < 2)
                        {
                            MainWindow.main.monApp_listbox.Items.Add(item.Subject + "  : " + item.Start.TimeOfDay.ToString());
                        }
                    }
                    else if (item.Start.DayOfWeek.ToString() == "Tuesday")
                    {
                        MainWindow.main.tueList.Add(item);
                        if (MainWindow.main.tueApp_listbox.Items.Count < 2)
                        {
                            MainWindow.main.tueApp_listbox.Items.Add(item.Subject + "  : " + item.Start.TimeOfDay.ToString());
                        }
                    }
                    else if (item.Start.DayOfWeek.ToString() == "Wednesday")
                    {
                        MainWindow.main.wedList.Add(item);
                        if (MainWindow.main.wedApp_listbox.Items.Count < 2)
                        {
                            MainWindow.main.wedApp_listbox.Items.Add(item.Subject + "  : " + item.Start.TimeOfDay.ToString());
                        }
                    }
                    else if (item.Start.DayOfWeek.ToString() == "Thursday")
                    {
                        MainWindow.main.thuList.Add(item);
                        if (MainWindow.main.thuApp_listbox.Items.Count < 2)
                        {
                            MainWindow.main.thuApp_listbox.Items.Add(item.Subject + "  : " + item.Start.TimeOfDay.ToString());
                        }
                    }
                    else if (item.Start.DayOfWeek.ToString() == "Friday")
                    {
                        MainWindow.main.friList.Add(item);
                        if (MainWindow.main.friApp_listbox.Items.Count < 2)
                        {
                            MainWindow.main.friApp_listbox.Items.Add(item.Subject + "  : " + item.Start.TimeOfDay.ToString());
                        }
                    }
                    else if (item.Start.DayOfWeek.ToString() == "Saturday")
                    {
                        MainWindow.main.satList.Add(item);
                        if (MainWindow.main.satApp_listbox.Items.Count < 2)
                        {
                            MainWindow.main.satApp_listbox.Items.Add(item.Subject + "  : " + item.Start.TimeOfDay.ToString());
                        }
                    }
                    else if (item.Start.DayOfWeek.ToString() == "Sunday")
                    {
                        MainWindow.main.sunList.Add(item);
                        if (MainWindow.main.sunApp_listbox.Items.Count < 2)
                        {
                            MainWindow.main.sunApp_listbox.Items.Add(item.Subject + "  : " + item.Start.TimeOfDay.ToString());
                        }
                    }
                }
                else if (item.Start.Day == currDateTime.AddDays(3).Day)
                {
                    if (item.Start.DayOfWeek.ToString() == "Monday")
                    {
                        MainWindow.main.monList.Add(item);
                        if (MainWindow.main.monApp_listbox.Items.Count < 2)
                        {
                            MainWindow.main.monApp_listbox.Items.Add(item.Subject + "  : " + item.Start.TimeOfDay.ToString());
                        }
                    }
                    else if (item.Start.DayOfWeek.ToString() == "Tuesday")
                    {
                        MainWindow.main.tueList.Add(item);
                        if (MainWindow.main.tueApp_listbox.Items.Count < 2)
                        {
                            MainWindow.main.tueApp_listbox.Items.Add(item.Subject + "  : " + item.Start.TimeOfDay.ToString());
                        }
                    }
                    else if (item.Start.DayOfWeek.ToString() == "Wednesday")
                    {
                        MainWindow.main.wedList.Add(item);
                        if (MainWindow.main.wedApp_listbox.Items.Count < 2)
                        {
                            MainWindow.main.wedApp_listbox.Items.Add(item.Subject + "  : " + item.Start.TimeOfDay.ToString());
                        }
                    }
                    else if (item.Start.DayOfWeek.ToString() == "Thursday")
                    {
                        MainWindow.main.thuList.Add(item);
                        if (MainWindow.main.thuApp_listbox.Items.Count < 2)
                        {
                            MainWindow.main.thuApp_listbox.Items.Add(item.Subject + "  : " + item.Start.TimeOfDay.ToString());
                        }
                    }
                    else if (item.Start.DayOfWeek.ToString() == "Friday")
                    {
                        MainWindow.main.friList.Add(item);
                        if (MainWindow.main.friApp_listbox.Items.Count < 2)
                        {
                            MainWindow.main.friApp_listbox.Items.Add(item.Subject + "  : " + item.Start.TimeOfDay.ToString());
                        }
                    }
                    else if (item.Start.DayOfWeek.ToString() == "Saturday")
                    {
                        MainWindow.main.satList.Add(item);
                        if (MainWindow.main.satApp_listbox.Items.Count < 2)
                        {
                            MainWindow.main.satApp_listbox.Items.Add(item.Subject + "  : " + item.Start.TimeOfDay.ToString());
                        }
                    }
                    else if (item.Start.DayOfWeek.ToString() == "Sunday")
                    {
                        MainWindow.main.sunList.Add(item);
                        if (MainWindow.main.sunApp_listbox.Items.Count < 2)
                        {
                            MainWindow.main.sunApp_listbox.Items.Add(item.Subject + "  : " + item.Start.TimeOfDay.ToString());
                        }
                    }
                }
                else if (item.Start.Day == currDateTime.AddDays(4).Day)
                {
                    if (item.Start.DayOfWeek.ToString() == "Monday")
                    {
                        MainWindow.main.monList.Add(item);
                        if (MainWindow.main.monApp_listbox.Items.Count < 2)
                        {
                            MainWindow.main.monApp_listbox.Items.Add(item.Subject + "  : " + item.Start.TimeOfDay.ToString());
                        }
                    }
                    else if (item.Start.DayOfWeek.ToString() == "Tuesday")
                    {
                        MainWindow.main.tueList.Add(item);
                        if (MainWindow.main.tueApp_listbox.Items.Count < 2)
                        {
                            MainWindow.main.tueApp_listbox.Items.Add(item.Subject + "  : " + item.Start.TimeOfDay.ToString());
                        }
                    }
                    else if (item.Start.DayOfWeek.ToString() == "Wednesday")
                    {
                        MainWindow.main.wedList.Add(item);
                        if (MainWindow.main.wedApp_listbox.Items.Count < 2)
                        {
                            MainWindow.main.wedApp_listbox.Items.Add(item.Subject + "  : " + item.Start.TimeOfDay.ToString());
                        }
                    }
                    else if (item.Start.DayOfWeek.ToString() == "Thursday")
                    {
                        MainWindow.main.thuList.Add(item);
                        if (MainWindow.main.thuApp_listbox.Items.Count < 2)
                        {
                            MainWindow.main.thuApp_listbox.Items.Add(item.Subject + "  : " + item.Start.TimeOfDay.ToString());
                        }
                    }
                    else if (item.Start.DayOfWeek.ToString() == "Friday")
                    {
                        MainWindow.main.friList.Add(item);
                        if (MainWindow.main.friApp_listbox.Items.Count < 2)
                        {
                            MainWindow.main.friApp_listbox.Items.Add(item.Subject + "  : " + item.Start.TimeOfDay.ToString());
                        }
                    }
                    else if (item.Start.DayOfWeek.ToString() == "Saturday")
                    {
                        MainWindow.main.satList.Add(item);
                        if (MainWindow.main.satApp_listbox.Items.Count < 2)
                        {
                            MainWindow.main.satApp_listbox.Items.Add(item.Subject + "  : " + item.Start.TimeOfDay.ToString());
                        }
                    }
                    else if (item.Start.DayOfWeek.ToString() == "Sunday")
                    {
                        MainWindow.main.sunList.Add(item);
                        if (MainWindow.main.sunApp_listbox.Items.Count < 2)
                        {
                            MainWindow.main.sunApp_listbox.Items.Add(item.Subject + "  : " + item.Start.TimeOfDay.ToString());
                        }
                    }
                }
                else if (item.Start.Day == currDateTime.AddDays(5).Day)
                {
                    if (item.Start.DayOfWeek.ToString() == "Monday")
                    {
                        MainWindow.main.monList.Add(item);
                        if (MainWindow.main.monApp_listbox.Items.Count < 2)
                        {
                            MainWindow.main.monApp_listbox.Items.Add(item.Subject + "  : " + item.Start.TimeOfDay.ToString());
                        }
                    }
                    else if (item.Start.DayOfWeek.ToString() == "Tuesday")
                    {
                        MainWindow.main.tueList.Add(item);
                        if (MainWindow.main.tueApp_listbox.Items.Count < 2)
                        {
                            MainWindow.main.tueApp_listbox.Items.Add(item.Subject + "  : " + item.Start.TimeOfDay.ToString());
                        }
                    }
                    else if (item.Start.DayOfWeek.ToString() == "Wednesday")
                    {
                        MainWindow.main.wedList.Add(item);
                        if (MainWindow.main.wedApp_listbox.Items.Count < 2)
                        {
                            MainWindow.main.wedApp_listbox.Items.Add(item.Subject + "  : " + item.Start.TimeOfDay.ToString());
                        }
                    }
                    else if (item.Start.DayOfWeek.ToString() == "Thursday")
                    {
                        MainWindow.main.thuList.Add(item);
                        if (MainWindow.main.thuApp_listbox.Items.Count < 2)
                        {
                            MainWindow.main.thuApp_listbox.Items.Add(item.Subject + "  : " + item.Start.TimeOfDay.ToString());
                        }
                    }
                    else if (item.Start.DayOfWeek.ToString() == "Friday")
                    {
                        MainWindow.main.friList.Add(item);
                        if (MainWindow.main.friApp_listbox.Items.Count < 2)
                        {
                            MainWindow.main.friApp_listbox.Items.Add(item.Subject + "  : " + item.Start.TimeOfDay.ToString());
                        }
                    }
                    else if (item.Start.DayOfWeek.ToString() == "Saturday")
                    {
                        MainWindow.main.satList.Add(item);
                        if (MainWindow.main.satApp_listbox.Items.Count < 2)
                        {
                            MainWindow.main.satApp_listbox.Items.Add(item.Subject + "  : " + item.Start.TimeOfDay.ToString());
                        }
                    }
                    else if (item.Start.DayOfWeek.ToString() == "Sunday")
                    {
                        MainWindow.main.sunList.Add(item);
                        if (MainWindow.main.sunApp_listbox.Items.Count < 2)
                        {
                            MainWindow.main.sunApp_listbox.Items.Add(item.Subject + "  : " + item.Start.TimeOfDay.ToString());
                        }
                    }
                }
                else if (item.Start.Day == currDateTime.AddDays(6).Day)
                {
                    if (item.Start.DayOfWeek.ToString() == "Monday")
                    {
                        MainWindow.main.monList.Add(item);
                        if (MainWindow.main.monApp_listbox.Items.Count < 2)
                        {
                            MainWindow.main.monApp_listbox.Items.Add(item.Subject + "  : " + item.Start.TimeOfDay.ToString());
                        }
                    }
                    else if (item.Start.DayOfWeek.ToString() == "Tuesday")
                    {
                        MainWindow.main.tueList.Add(item);
                        if (MainWindow.main.tueApp_listbox.Items.Count < 2)
                        {
                            MainWindow.main.tueApp_listbox.Items.Add(item.Subject + "  : " + item.Start.TimeOfDay.ToString());
                        }
                    }
                    else if (item.Start.DayOfWeek.ToString() == "Wednesday")
                    {
                        MainWindow.main.wedList.Add(item);
                        if (MainWindow.main.wedApp_listbox.Items.Count < 2)
                        {
                            MainWindow.main.wedApp_listbox.Items.Add(item.Subject + "  : " + item.Start.TimeOfDay.ToString());
                        }
                    }
                    else if (item.Start.DayOfWeek.ToString() == "Thursday")
                    {
                        MainWindow.main.thuList.Add(item);
                        if (MainWindow.main.thuApp_listbox.Items.Count < 2)
                        {
                            MainWindow.main.thuApp_listbox.Items.Add(item.Subject + "  : " + item.Start.TimeOfDay.ToString());
                        }
                    }
                    else if (item.Start.DayOfWeek.ToString() == "Friday")
                    {
                        MainWindow.main.friList.Add(item);
                        if (MainWindow.main.friApp_listbox.Items.Count < 2)
                        {
                            MainWindow.main.friApp_listbox.Items.Add(item.Subject + "  : " + item.Start.TimeOfDay.ToString());
                        }
                    }
                    else if (item.Start.DayOfWeek.ToString() == "Saturday")
                    {
                        MainWindow.main.satList.Add(item);
                        if (MainWindow.main.satApp_listbox.Items.Count < 2)
                        {
                            MainWindow.main.satApp_listbox.Items.Add(item.Subject + "  : " + item.Start.TimeOfDay.ToString());
                        }
                    }
                    else if (item.Start.DayOfWeek.ToString() == "Sunday")
                    {
                        MainWindow.main.sunList.Add(item);
                        if (MainWindow.main.sunApp_listbox.Items.Count < 2)
                        {
                            MainWindow.main.sunApp_listbox.Items.Add(item.Subject + "  : " + item.Start.TimeOfDay.ToString());
                        }
                    }
                }
            }
            if (MainWindow.main.monList.Count >= 3)
            {
                MainWindow.main.monApp_listbox.Items.Add("...more...");
            }
            if (MainWindow.main.tueList.Count >= 3)
            {
                MainWindow.main.tueApp_listbox.Items.Add("...more...");
            }
            if (MainWindow.main.wedList.Count >= 3)
            {
                MainWindow.main.wedApp_listbox.Items.Add("...more...");
            }
            if (MainWindow.main.thuList.Count >= 3)
            {
                MainWindow.main.thuApp_listbox.Items.Add("...more...");
            }
            if (MainWindow.main.friList.Count >= 3)
            {
                MainWindow.main.friApp_listbox.Items.Add("...more...");
            }
            if (MainWindow.main.satList.Count >= 3)
            {
                MainWindow.main.satApp_listbox.Items.Add("...more...");
            }
            if (MainWindow.main.sunList.Count >= 3)
            {
                MainWindow.main.sunApp_listbox.Items.Add("...more...");
            }
        }
Exemplo n.º 27
0
        static void Main(string[] args)
        {
            Outlook.Application app       = new Microsoft.Office.Interop.Outlook.Application();
            Outlook._NameSpace  nameSpace = app.GetNamespace("MAPI");
            nameSpace.Logon(null, null, false, false);
            Outlook.Folder folder = (Outlook.Folder)app.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderDrafts);

            Outlook.MailItem msg;

            //Making an Excel file
            Excel.Application xlApp;
            Excel.Workbook    xlWorkBook;
            Excel.Worksheet   xlWorkSheet;
            object            misValue = System.Reflection.Missing.Value;

            xlApp       = new Microsoft.Office.Interop.Excel.Application();
            xlWorkBook  = xlApp.Workbooks.Add(misValue);
            xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);

            //Passing the files with address of msg file to StreamReader
            System.IO.StreamReader file = new System.IO.StreamReader(@"list_of_msg_files.txt");

            const string PR_SMTP_ADDRESS = "http://schemas.microsoft.com/mapi/proptag/0x39FE001E";

            int    count = 1; //In excel count starts from 1
            string filePath, smtpAddress = "";

            //reading name of each msg file from
            while ((filePath = file.ReadLine()) != null)
            {
                try
                {
                    check++;
                    msg = (Outlook.MailItem)app.Session.OpenSharedItem(filePath);
                }
                catch (Exception ex)
                {
                    System.Console.WriteLine(filePath);
                    if (check > 11093)
                    {
                        break;
                    }
                    else
                    {
                        continue;
                    }
                }


                try
                {
                    //Fiding Sender Information
                    Outlook._MailItem temp = ((Outlook._MailItem)msg).Reply();

                    Outlook.Recipient        sender = temp.Recipients[1];
                    Outlook.PropertyAccessor xx     = sender.PropertyAccessor;


                    try //For some companies, when an employee leaves, the local email address is deleted
                    {
                        smtpAddress = xx.GetProperty(PR_SMTP_ADDRESS).ToString();
                    }
                    catch (Exception ex)
                    {
                        smtpAddress = "NAN";
                    }

                    temp.Delete();

                    xlWorkSheet.Cells[count, 1] = (sender.Name == null) ? "" : sender.Name;
                }
                catch (Exception e) //ignore!!
                {
                    xlWorkSheet.Cells[count, 1] = (msg.SenderName == null) ? "" : msg.SenderName;
                }


                xlWorkSheet.Cells[count, 2] = (smtpAddress == null) ? "" : smtpAddress;

                //subject
                xlWorkSheet.Cells[count, 3] = (msg.Subject == null) ? "" : msg.Subject;

                //Recipients
                smtpAddress = "";
                string             names  = "";
                Outlook.Recipients recips = msg.Recipients;

                foreach (Outlook.Recipient recip in recips)
                {
                    Outlook.PropertyAccessor pa = recip.PropertyAccessor;

                    string tmp;
                    try // if email address is not there
                    {
                        tmp = pa.GetProperty(PR_SMTP_ADDRESS).ToString();
                    }
                    catch (Exception ex)
                    {
                        tmp = recip.Name;
                    }

                    smtpAddress = smtpAddress + "," + tmp;
                    names       = names + "," + recip.Name;
                }


                xlWorkSheet.Cells[count, 4] = (smtpAddress == null) ? "" : smtpAddress;
                xlWorkSheet.Cells[count, 5] = (names == null) ? "" : names;

                //In case you need CreationTime
                //xlWorkSheet.Cells[count, 6] = (msg.CreationTime == null) ? "" : msg.CreationTime.ToShortDateString();
                //xlWorkSheet.Cells[count, 7] = (msg.ReceivedTime == null) ? "" : msg.ReceivedTime.ToShortDateString();

                xlWorkSheet.Cells[count, 6] = (msg.SentOn == null) ? "" : msg.SentOn.Day + "-" + msg.SentOn.Month + "-" + msg.SentOn.Year;
                xlWorkSheet.Cells[count, 7] = (msg.Body == null) ? "" : msg.Body;
                xlWorkSheet.Cells[count, 8] = filePath;


                string attached = "";
                for (int i = 0; i < msg.Attachments.Count; i++)
                {
                    attached += "," + msg.Attachments[i + 1].FileName;
                }


                xlWorkSheet.Cells[count, 9] = attached;

                count++;
            }


            file.Close();

            xlWorkBook.SaveAs("Emails.xls", Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
            xlWorkBook.Close(true, misValue, misValue);
            xlApp.Quit();

            System.Console.ReadLine();
        }
Exemplo n.º 28
0
        private void buttonMoveMailItem_Click(object sender, EventArgs e)
        {
            string
                folderName = "test";

            try
            {
                Outlook.MailItem
                    mailItem = null;

                Outlook._NameSpace
                    nameSpace = null;

                Outlook.MAPIFolder
                    defaultFolder = null,
                    parentFolder  = null,
                    destFolder    = null;

                Outlook.Explorer
                    explorer = null;

                try
                {
                    if ((mailItem = OutlookItem as Outlook.MailItem) != null &&
                        (nameSpace = mailItem.Application.GetNamespace("MAPI")) != null &&
                        (defaultFolder = nameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)) != null &&
                        (parentFolder = defaultFolder.Parent as Outlook.MAPIFolder) != null &&
                        (destFolder = parentFolder.Folders[folderName]) != null &&
                        (explorer = mailItem.Application.ActiveExplorer()) != null)
                    {
                        mailItem.Move(destFolder);
                        explorer.CurrentFolder = destFolder;
                        explorer.CurrentFolder.Display();
                    }
                }
                finally
                {
                    if (explorer != null)
                    {
                        Marshal.ReleaseComObject(explorer);
                        explorer = null;
                    }

                    if (destFolder != null)
                    {
                        Marshal.ReleaseComObject(destFolder);
                        destFolder = null;
                    }

                    if (parentFolder != null)
                    {
                        Marshal.ReleaseComObject(parentFolder);
                        parentFolder = null;
                    }

                    if (defaultFolder != null)
                    {
                        Marshal.ReleaseComObject(defaultFolder);
                        defaultFolder = null;
                    }

                    if (nameSpace != null)
                    {
                        Marshal.ReleaseComObject(nameSpace);
                        nameSpace = null;
                    }

                    if (mailItem != null)
                    {
                        Marshal.ReleaseComObject(mailItem);
                        mailItem = null;
                    }
                }
            }
            catch (Exception eException)
            {
                string msg;

                ThisAddIn.WriteToLog(msg = eException.GetType().FullName + Environment.NewLine + "Message: " + eException.Message + Environment.NewLine + (eException.InnerException != null && !string.IsNullOrEmpty(eException.InnerException.Message) ? "InnerException.Message" + eException.InnerException.Message + Environment.NewLine : string.Empty) + "StackTrace:" + Environment.NewLine + eException.StackTrace);
                textBoxLog.Text          = msg;
            }
        }
Exemplo n.º 29
0
        private void buttonFindMailItem_Click(object sender, EventArgs e)
        {
            try
            {
                Outlook.MailItem
                    mailItem = null;

                Outlook._NameSpace
                    nameSpace = null;

                Outlook.MAPIFolder
                    defaultFolder = null;

                Outlook.Items
                    items = null;

                try
                {
                    if ((mailItem = OutlookItem as Outlook.MailItem) != null &&
                        (nameSpace = mailItem.Application.GetNamespace("MAPI")) != null &&
                        (defaultFolder = nameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)) != null)
                    {
                        string
                            filter = "@SQL=\"http://schemas.microsoft.com/mapi/string/{00020329-0000-0000-C000-000000000046}/TestUserProperty/0000001f\" = 'UserProperty'";

                        items = defaultFolder.Items.Restrict(filter);

                        filter = "@SQL=\"http://schemas.microsoft.com/mapi/string/{00020329-0000-0000-C000-000000000046}/TestUserProperty/0000001f\" is null";
                        items  = defaultFolder.Items.Restrict(filter);

                        filter = "@SQL=\"http://schemas.microsoft.com/mapi/string/{00020329-0000-0000-C000-000000000046}/TestUserProperty/0000001f\" is not null";
                        items  = defaultFolder.Items.Restrict(filter);

                        string
                            TransportMessageHeadersSchema =
                            #if !TRANSPORT_MESSAGE_HEADERS_W
                            PR_TRANSPORT_MESSAGE_HEADERS
                            #else
                            PR_TRANSPORT_MESSAGE_HEADERS_W
                            #endif
                        ,
                            header = (string)mailItem.PropertyAccessor.GetProperty(TransportMessageHeadersSchema);

                        filter = string.Format("@SQL=\"{0}\" like '%{1}%'", TransportMessageHeadersSchema, "MySuperPuperTag: blah-blah-blah");
                        items  = defaultFolder.Items.Restrict(filter);

                        filter = string.Format("[LastModificationTime] > \"{0}\"", new DateTime(2011, 12, 8, 16, 0, 0).ToString("g"));
                        items  = defaultFolder.Items.Restrict(filter);
                    }
                }
                finally
                {
                    if (items != null)
                    {
                        Marshal.ReleaseComObject(items);
                        items = null;
                    }

                    if (defaultFolder != null)
                    {
                        Marshal.ReleaseComObject(defaultFolder);
                        defaultFolder = null;
                    }

                    if (nameSpace != null)
                    {
                        Marshal.ReleaseComObject(nameSpace);
                        nameSpace = null;
                    }

                    if (mailItem != null)
                    {
                        Marshal.ReleaseComObject(mailItem);
                        mailItem = null;
                    }
                }
            }
            catch (Exception eException)
            {
                string msg;

                ThisAddIn.WriteToLog(msg = eException.GetType().FullName + Environment.NewLine + "Message: " + eException.Message + Environment.NewLine + (eException.InnerException != null && !string.IsNullOrEmpty(eException.InnerException.Message) ? "InnerException.Message" + eException.InnerException.Message + Environment.NewLine : string.Empty) + "StackTrace:" + Environment.NewLine + eException.StackTrace);
                textBoxLog.Text          = msg;
            }
        }
Exemplo n.º 30
0
        private void buttonGetFolders_Click(object sender, EventArgs e)
        {
            try
            {
                Outlook.MailItem
                    mailItem = null;

                Outlook._NameSpace
                    nameSpace = null;

                Outlook.MAPIFolder
                    defaultFolder = null,
                    parentFolder  = null,
                    tmpFolder     = null;

                try
                {
                    if ((mailItem = OutlookItem as Outlook.MailItem) != null &&
                        (nameSpace = mailItem.Application.GetNamespace("MAPI")) != null &&
                        (defaultFolder = nameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)) != null &&
                        (parentFolder = defaultFolder.Parent as Outlook.MAPIFolder) != null)
                    {
                        string
                            tmpString;

                        if (!string.IsNullOrEmpty(tmpString = textBoxLog.Text.Trim()) &&
                            (tmpFolder = GetFolder(parentFolder, tmpString)) != null)
                        {
                            tmpFolder = GetFolder(tmpFolder, "Inbox");
                        }

                        tmpString = string.Empty;
                        foreach (Outlook.MAPIFolder f in parentFolder.Folders)
                        {
                            if (!string.IsNullOrEmpty(tmpString))
                            {
                                tmpString += " ";
                            }

                            tmpString += f.FolderPath;
                        }

                        textBoxLog.Text = string.Format("{0} {1} {2}", parentFolder.FullFolderPath, parentFolder.FolderPath, parentFolder.Folders.Count);
                    }
                }
                finally
                {
                    if (tmpFolder != null)
                    {
                        Marshal.ReleaseComObject(tmpFolder);
                        tmpFolder = null;
                    }

                    if (parentFolder != null)
                    {
                        Marshal.ReleaseComObject(parentFolder);
                        parentFolder = null;
                    }

                    if (defaultFolder != null)
                    {
                        Marshal.ReleaseComObject(defaultFolder);
                        defaultFolder = null;
                    }

                    if (nameSpace != null)
                    {
                        Marshal.ReleaseComObject(nameSpace);
                        nameSpace = null;
                    }

                    if (mailItem != null)
                    {
                        Marshal.ReleaseComObject(mailItem);
                        mailItem = null;
                    }
                }
            }
            catch (Exception eException)
            {
                string msg;

                ThisAddIn.WriteToLog(msg = eException.GetType().FullName + Environment.NewLine + "Message: " + eException.Message + Environment.NewLine + (eException.InnerException != null && !string.IsNullOrEmpty(eException.InnerException.Message) ? "InnerException.Message" + eException.InnerException.Message + Environment.NewLine : string.Empty) + "StackTrace:" + Environment.NewLine + eException.StackTrace);
                textBoxLog.Text          = msg;
            }
        }
Exemplo n.º 31
0
        private void buttonCreateFolder_Click(object sender, EventArgs e)
        {
            string
                folderName;

            if (string.IsNullOrEmpty(folderName = textBoxLog.Text.Trim()))
            {
                return;
            }

            try
            {
                Outlook.MailItem
                    mailItem = null;

                Outlook._NameSpace
                    nameSpace = null;

                Outlook.MAPIFolder
                    defaultFolder = null,
                    parentFolder  = null,
                    tmpFolder     = null;

                Outlook.Explorer
                    explorer = null;

                try
                {
                    if ((mailItem = OutlookItem as Outlook.MailItem) != null &&
                        (nameSpace = mailItem.Application.GetNamespace("MAPI")) != null &&
                        (defaultFolder = nameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)) != null &&
                        (parentFolder = defaultFolder.Parent as Outlook.MAPIFolder) != null &&
                        (explorer = mailItem.Application.ActiveExplorer()) != null)
                    {
                        if ((tmpFolder = GetFolder(parentFolder, folderName)) == null)
                        {
                            tmpFolder = parentFolder.Folders.Add(folderName, Outlook.OlDefaultFolders.olFolderDrafts);
                        }

                        string
                            folderFolderName = "Inbox";

                        if (GetFolder(tmpFolder, folderFolderName) == null)
                        {
                            tmpFolder.Folders.Add(folderFolderName, Outlook.OlDefaultFolders.olFolderDrafts);
                        }

                        folderFolderName = "Sent Items";
                        if (GetFolder(tmpFolder, folderFolderName) == null)
                        {
                            tmpFolder.Folders.Add(folderFolderName, Outlook.OlDefaultFolders.olFolderDrafts);
                        }

                        explorer.CurrentFolder = parentFolder.Folders[folderName];
                        explorer.CurrentFolder.Display();
                    }
                }
                finally
                {
                    if (explorer != null)
                    {
                        Marshal.ReleaseComObject(explorer);
                        explorer = null;
                    }

                    if (tmpFolder != null)
                    {
                        Marshal.ReleaseComObject(tmpFolder);
                        tmpFolder = null;
                    }

                    if (parentFolder != null)
                    {
                        Marshal.ReleaseComObject(parentFolder);
                        parentFolder = null;
                    }

                    if (defaultFolder != null)
                    {
                        Marshal.ReleaseComObject(defaultFolder);
                        defaultFolder = null;
                    }

                    if (nameSpace != null)
                    {
                        Marshal.ReleaseComObject(nameSpace);
                        nameSpace = null;
                    }

                    if (mailItem != null)
                    {
                        Marshal.ReleaseComObject(mailItem);
                        mailItem = null;
                    }
                }
            }
            catch (Exception eException)
            {
                string msg;

                ThisAddIn.WriteToLog(msg = eException.GetType().FullName + Environment.NewLine + "Message: " + eException.Message + Environment.NewLine + (eException.InnerException != null && !string.IsNullOrEmpty(eException.InnerException.Message) ? "InnerException.Message" + eException.InnerException.Message + Environment.NewLine : string.Empty) + "StackTrace:" + Environment.NewLine + eException.StackTrace);
                textBoxLog.Text          = msg;
            }
        }
Exemplo n.º 32
0
 public MailProcessor(IEngine engine, Outlook._NameSpace session)
 {
     _engine  = engine ?? throw new ArgumentNullException(nameof(engine));
     _session = session ?? throw new ArgumentNullException(nameof(session));
 }
        public ReportCrime SaveReport(long?id, string typeOfCrime, string location, string date, string time, string name, string contactNo, string status)
        {
            /*  Authenticate(PrivilegeType.ReportCrimeMaintenance);*/
            ReportCrime rep = new ReportCrime();
            DataTable   dt;


            //  Outlook.Folder deletee = new Outlook.Folder();

            //  Outlook.MailItem info = new Outlook.MailItem();
            Outlook._Application _app  = new Outlook.Application();
            Outlook._NameSpace   _ns   = _app.GetNamespace("MAPI");
            Outlook.MAPIFolder   inbox = _ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
            // Outlook.MAPIFolder delete = _ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderDeletedItems);
            _ns.SendAndReceive(true);



            dt = new DataTable("Inbox");
            dt.Columns.Add("Subject", typeof(string));
            dt.Columns.Add("Sender", typeof(string));
            dt.Columns.Add("Body", typeof(string));
            dt.Columns.Add("Date", typeof(string));

            string subItem = "";



            foreach (Outlook.MailItem item in inbox.Items)
            {
                if (item.UnRead == true)
                {
                    subItem = item.Subject;
                    int testChar = subItem.IndexOf("-");

                    if (subItem.IndexOf("-") > 0)
                    {
                        for (int x = 0; x < subItem.Length; x++)
                        {
                            if (subItem.Substring(x, 1) == "-" && testChar == x)
                            {
                                typeOfCrime = subItem.Substring(0, x);
                            }

                            if (subItem.Substring(x, 1) == "-" && testChar != x)
                            {
                                name = subItem.Substring(typeOfCrime.Length + 1, x - typeOfCrime.Length - 1);

                                contactNo = subItem.Substring(x + 1);
                            }
                        }
                    }
                    else
                    {
                        typeOfCrime = item.Subject;
                        name        = "Anonymous";
                        contactNo   = "Anonymous";
                    }


                    status = "Pending";


                    location = item.Body;

                    date = item.SentOn.ToLongDateString();
                    time = item.SentOn.ToLongTimeString();

                    rep.Status      = status;
                    rep.TypeOfCrime = typeOfCrime;
                    rep.Name        = name;
                    rep.ContactNo   = contactNo;
                    rep.Location    = location;
                    rep.Date        = date;
                    rep.Time        = time;



                    DataContext.ReportCrimeSet.Add(rep);
                    DataContext.SaveChanges();
                }

                if (item.UnRead)
                {
                    item.UnRead = false;
                    item.Save();
                }
            }


            //  _serialPort.Write("1");



            //_serialPort.Close();



            //Outlook.ContactItem contact =

            // _ns.geGetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts).
            // Items.
            // Find(
            // string.Format("[LastName]='{0}' AND [FirstName]='{1}'",
            // lastName, firstName))
            // as Outlook.ContactItem;

            //if (contact != null)
            //{
            //    contact.Delete();
            //}



            return(rep);
        }
Exemplo n.º 34
0
        public List<string> TriggerOutlook()
        {
           
            List<string> folders = new List<string>();
            try
            {
                app = new Microsoft.Office.Interop.Outlook.Application();
                ns = app.GetNamespace("MAPI");
                foreach (MAPIFolder folder in ns.Folders)
                {
                    folders = GetEmailFolders(folder);

                }
                folders.Sort();
            }
            catch (System.Exception ex)
            {
            }
            return folders;
        }
Exemplo n.º 35
0
        private void GetEmail()
        {
            Email.Application app         = null;
            Email._NameSpace  ns          = null;
            Email.MailItem    item        = null;
            Email.MAPIFolder  inboxFolder = null;
            Email.MAPIFolder  subFolder   = null;
            Email.MAPIFolder  NewIncident = null;
            Email.MAPIFolder  FollowUp    = null;
            Email.MAPIFolder  None        = null;
            string            EmailType   = string.Empty;

            try
            {
                app = new Email.Application();
                ns  = app.GetNamespace("MAPI");
                ns.Logon(null, null, false, false);

                inboxFolder = ns.GetDefaultFolder(Email.OlDefaultFolders.olFolderInbox);
                subFolder   = inboxFolder.Folders[EMailFolder]; //folder.Folders[1]; also works
                NewIncident = inboxFolder.Folders["NewIncident"];
                FollowUp    = inboxFolder.Folders["FollowUp"];
                None        = inboxFolder.Folders["None"];
                //Console.WriteLine("Folder Name: {0}, EntryId: {1}", subFolder.Name, subFolder.EntryID);
                //Console.WriteLine("Num Items: {0}", subFolder.Items.Count.ToString());
                if (subFolder.Items.Count != 0)
                {
                    for (int i = 1; i <= subFolder.Items.Count; i++)
                    {
                        item = (Email.MailItem)subFolder.Items[i];
                        string Body = item.Body;
                        if (TrainorTest.ToLower().Equals("train"))
                        {
                            CreateDS(Body);
                        }
                        else
                        {
                            EmailType = ClassifyMail(Body);
                            if (EmailType.ToLower().Equals("newincident"))
                            {
                                item.Move(NewIncident);
                            }
                            else if (EmailType.ToLower().Equals("followup"))
                            {
                                item.Move(FollowUp);
                            }
                            else
                            {
                                item.Move(None);
                            }
                        }
                    }
                }
                else
                {
                    ErrCode  = 204;
                    ErrDesc += "Message: No Email found in " + EMailFolder + " Folder." + Environment.NewLine;

                    Message = "No Email found in " + EMailFolder + " Folder.";
                }
            }
            catch (System.Runtime.InteropServices.COMException ex)
            {
                ErrCode  = 503;
                ErrDesc += "Message: " + ex.Message + Environment.NewLine + "Inner Exception: " + ex.InnerException + Environment.NewLine;

                Message = "Inside GetEmail() Exception: Error While Getting Email Form Outlook. " + ex.Message;
                //Console.WriteLine(ex.ToString());
            }
            finally
            {
                ns          = null;
                app         = null;
                inboxFolder = null;
            }
        }
Exemplo n.º 36
0
 public List<MAPIFolder> GetSelectedEmailFolders(List<string> folderNames)
 {
     app = new Microsoft.Office.Interop.Outlook.Application();
     ns = app.GetNamespace("MAPI");
     
     foreach (MAPIFolder subFolder in ns.Folders)
     {
         GetSelectedEmailFolders(subFolder, folderNames);
     }
     return outlookFolders;
 }
Exemplo n.º 37
-1
		public OutlookPortal()
		{
			oApp = new Microsoft.Office.Interop.Outlook.Application();
			oNameSpace = oApp.GetNamespace("MAPI");
			oOutboxFolder = oNameSpace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderOutbox);
			oNameSpace.Logon(null, null, false, false);
			oMailItem =	(Microsoft.Office.Interop.Outlook._MailItem)oApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
			
		}