Exemplo n.º 1
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));
            }
        }
		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.º 3
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.º 4
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.º 5
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.º 6
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.º 7
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.º 8
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.º 9
-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);
			
		}