예제 #1
0
        public Form_Main()
        {
            InitializeComponent();

            dateTimePicker_MaxDateMissions.Value = DateTime.Now.AddMonths(1);
            dateTimePicker_MinDate.Value         = DateTime.Now.AddDays(-4);

            dateTimePicker_MinDate.ValueChanged         += dateTimePicker_MinDate_ValueChanged;
            dateTimePicker_MaxDateMissions.ValueChanged += dateTimePicker_MaxDateMissions_ValueChanged;
            Microsoft.Office.Interop.Outlook.Application app = new Microsoft.Office.Interop.Outlook.Application();
            Microsoft.Office.Interop.Outlook.NameSpace   ns  = app.GetNamespace("MAPI");
            Outlook.MAPIFolder f = ns.GetDefaultFolder(OlDefaultFolders.olFolderInbox);
            //   Thread.Sleep(5000);
            //   Microsoft.Office.Interop.Outlook.MailItem mailItem = (Outlook.MailItem)app.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
            toolStripStatusLabel_Name.Text = "חובר כ: " + app.Session.CurrentUser.Name;
            LoadMissions(dateTimePicker_MinDate.Value, dateTimePicker_MaxDateMissions.Value);
            //         List<string> lst = new List<string>();
            //         lst.Add(("*****@*****.**"));
            //    AssignMission(DateTime.Now.AddDays(1), "בוsdfא", "asdasasd",lst);
            //       mailItem.Subject = "This is the subject";
            //    mailItem.To = "*****@*****.**";
            //     mailItem.Body = "This is the message.";
            //     mailItem.Importance = Outlook.OlImportance.olImportanceLow;
            //      mailItem.Display(false);
        }
예제 #2
0
        private void FindContactEmailByName(string firstName, string lastName)
        {
            Microsoft.Office.Interop.Outlook.Application app = new Microsoft.Office.Interop.Outlook.Application();
            Microsoft.Office.Interop.Outlook.NameSpace   outlookNameSpace = app.GetNamespace("MAPI");
            Outlook.MAPIFolder f = outlookNameSpace.GetDefaultFolder(OlDefaultFolders.olFolderInbox);


            Outlook.MAPIFolder contactsFolder =
                outlookNameSpace.GetDefaultFolder(
                    Microsoft.Office.Interop.Outlook.
                    OlDefaultFolders.olFolderContacts);

            Outlook.Items contactItems = contactsFolder.Items;

            try
            {
                Outlook.ContactItem contact =
                    (Outlook.ContactItem)contactItems.
                    Find(String.Format("[FirstName]='{0}' and "
                                       + "[LastName]='{1}'", firstName, lastName));
                if (contact != null)
                {
                    //  return contact;
                    contact.Display(true);
                }
                else
                {
                    MessageBox.Show("The contact information was not found.");
                }
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
        }
예제 #3
0
        public AddMission(Mission m)
        {
            InitializeComponent();
            Region = System.Drawing.Region.FromHrgn(CreateRoundRectRgn(0, 0, Width, Height, 100, 100));
            dateTimePicker_dueDate.Value = DateTime.Now.AddDays(7);

            this.updateMission = true;
            Microsoft.Office.Interop.Outlook.Application app = new Microsoft.Office.Interop.Outlook.Application();
            Microsoft.Office.Interop.Outlook.NameSpace   ns  = app.GetNamespace("MAPI");
            Outlook.MAPIFolder f = ns.GetDefaultFolder(OlDefaultFolders.olFolderInbox);
            foreach (string reci in m.Recipients)
            {
                listBox_Recipients.Items.Add(reci);
            }
            this.currentMission   = m;
            textBox_Sbuject.Text  = m.Title;
            richTextBox_Body.Text = m.Body;

            dateTimePicker_dueDate.Value = m.DueDate;

            this.orginizer   = app.Session.CurrentUser.Name;
            label_Title.Text = "עדכן משימה";
            button_Add.Text  = "עדכן";

            EnableButtonsInUpdate(m.Orginizer);
        }
예제 #4
0
        public void LoadMissions(DateTime min, DateTime max)
        {
            missions     = new List <Mission>();
            appointments = new List <AppointmentItem>();
            if (dataGridView_Display.InvokeRequired)
            {
                dataGridView_Display.Invoke(new MethodInvoker(delegate { dataGridView_Display.Rows.Clear(); }));
            }
            else
            {
                dataGridView_Display.Rows.Clear();
            }


            Microsoft.Office.Interop.Outlook.Application app = new Microsoft.Office.Interop.Outlook.Application();
            Microsoft.Office.Interop.Outlook.NameSpace   ns  = app.GetNamespace("MAPI");
            Outlook.MAPIFolder f = ns.GetDefaultFolder(OlDefaultFolders.olFolderInbox);
            // Thread.Sleep(5000);
            Outlook.Folder calFolder =
                app.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar) as Outlook.Folder;

            Outlook.Items items = GetAppointmentsInRange(calFolder, dateTimePicker_MinDate.Value, dateTimePicker_MaxDateMissions.Value);
            //   double val = 0;
            if (items == null)
            {
                return;
            }

            for (int i = 0; i < items.Count; i++)
            {
                Outlook.AppointmentItem item = (Outlook.AppointmentItem)items[i + 1];
                if (item.Companies == "Missionator")
                {
                    if (dataGridView_Display.InvokeRequired)
                    {
                        dataGridView_Display.Invoke(new MethodInvoker(delegate
                        {
                            addRows(item);
                        }));
                    }
                    else
                    {
                        addRows(item);
                    }
                }
                if (statusStrip_Status.InvokeRequired)
                {
                    statusStrip_Status.Invoke(new MethodInvoker(delegate
                    {
                        toolStripProgressBar_Progress.Value = (((i + 1) * 100) / items.Count);
                    }));
                }
                else
                {
                    toolStripProgressBar_Progress.Value = (((i + 1) * 100) / items.Count);
                }
                System.Windows.Forms.Application.DoEvents();
            }
        }
예제 #5
0
        public AddMission()
        {
            InitializeComponent();
            Region = System.Drawing.Region.FromHrgn(CreateRoundRectRgn(0, 0, Width, Height, 100, 100));
            dateTimePicker_dueDate.Value = DateTime.Now.AddDays(7);

            Microsoft.Office.Interop.Outlook.Application app = new Microsoft.Office.Interop.Outlook.Application();
            Microsoft.Office.Interop.Outlook.NameSpace   ns  = app.GetNamespace("MAPI");
            Outlook.MAPIFolder f = ns.GetDefaultFolder(OlDefaultFolders.olFolderInbox);
            listBox_Recipients.Items.Add(app.Session.CurrentUser.Address);
            this.orginizer = app.Session.CurrentUser.Name;
        }
예제 #6
0
        protected void populateAddressListFromOutlook()
        {
            DateTime startDate, endDate;

            endDate   = DateTime.Today;
            startDate = endDate.AddDays(-30);

            // app = new Microsoft.Office.Interop.Outlook.Application(); - this line will create problem with Outlook 2013 sometimes
            app = this.Application;
            //}
            ns = app.GetNamespace("MAPI");


            calendar = ns.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderCalendar);

            String StringToCheck = "";

            StringToCheck = "[Start] >= " + "\"" + startDate.ToString().Substring(0, startDate.ToString().IndexOf(" ")) + "\""
                            + " AND [End] <= \"" + endDate.ToString().Substring(0, endDate.ToString().IndexOf(" ")) + "\"";


            Microsoft.Office.Interop.Outlook.Items oItems = (Microsoft.Office.Interop.Outlook.Items)calendar.Items;
            Microsoft.Office.Interop.Outlook.Items restricted;

            oItems.Sort("[Start]", false);
            oItems.IncludeRecurrences = true;

            restricted = oItems.Restrict(StringToCheck);
            restricted.Sort("[Start]", false);

            restricted.IncludeRecurrences = true;
            Microsoft.Office.Interop.Outlook.AppointmentItem oAppt = (Microsoft.Office.Interop.Outlook.AppointmentItem)restricted.GetFirst();

            Dictionary <String, String> comboDict = new Dictionary <string, string>();

            comboDict.Add("ALL", "ALL");

            //Loop through each appointment item to find out the unique recipient list and add to the combo box
            while (oAppt != null)
            {
                oAppt = (Microsoft.Office.Interop.Outlook.AppointmentItem)restricted.GetNext();

                if (oAppt != null)
                {
                    foreach (Microsoft.Office.Interop.Outlook.Recipient rcp in oAppt.Recipients)
                    {
                        //Display the email id in bracket along with the name in case the name rcp.Name does not contain the email address
                        //This will help in situtation where the the same recipient with multiple emails address need to be distinguised
                        String recpDisplayString = rcp.Name.IndexOf("@") < 0 ? rcp.Name + "(" + rcp.Address + ")" : rcp.Name;

                        if (!comboDict.ContainsKey(recpDisplayString))
                        {
                            comboDict.Add(recpDisplayString, recpDisplayString);
                            if (recpDisplayString != null && !emailNameMappingDict.ContainsKey(recpDisplayString))
                            {
                                emailNameMappingDict.Add(recpDisplayString, rcp.Address != null ? rcp.Address : rcp.Name);
                            }
                            if (rcp.Name != null && !MOM_Form.autoCompleteList.Contains(recpDisplayString))
                            {
                                MOM_Form.autoCompleteList.Add(recpDisplayString);
                            }
                        }
                    }
                }
            }

            //listBox_AddrList.DataSource = new BindingSource(comboDict, null);
            //listBox_AddrList.DisplayMember = "Value";
            //listBox_AddrList.ValueMember = "Key";
            //listBox_AddrList.SelectedValue = "ALL";

            populateAutoCompleteList(startDate, endDate);
        }
        public string GetSMTPAddress(Outlook.MailItem mailItem)
        {
            if (mailItem.SendUsingAccount != null &&
                !string.IsNullOrWhiteSpace(mailItem.SendUsingAccount.SmtpAddress))
                return mailItem.SendUsingAccount.SmtpAddress;

            if (!string.IsNullOrWhiteSpace(mailItem.SenderEmailAddress) &&
                !mailItem.SenderEmailType.ToUpper().Equals("EX"))
                return mailItem.SenderEmailAddress;

            // This can be x509 for exchange accounts
            if (mailItem.SendUsingAccount != null &&
                mailItem.SendUsingAccount.AccountType != 0 && /* Verify not exchange account */
                mailItem.SendUsingAccount.CurrentUser != null &&
                mailItem.SendUsingAccount.CurrentUser.Address != null)
                return mailItem.SendUsingAccount.CurrentUser.Address;

            Microsoft.Office.Interop.Outlook.Recipient recip;
            Outlook.ExchangeUser exUser;
            Microsoft.Office.Interop.Outlook.Application oOutlook =
                   new Microsoft.Office.Interop.Outlook.Application();
            Outlook.NameSpace oNS = oOutlook.GetNamespace("MAPI");

            if (mailItem.SenderEmailType.ToUpper().Equals("EX"))
            {
                recip = oNS.CreateRecipient(mailItem.SenderName);
                exUser = recip.AddressEntry.GetExchangeUser();
                return exUser.PrimarySmtpAddress;
            }

            throw new Exception("Error, unable to determine senders address.");
        }
예제 #8
0
        public bool AssignMission(Mission m)
        {
            //  try
            //   {
            Microsoft.Office.Interop.Outlook.Application app = new Microsoft.Office.Interop.Outlook.Application();
            Microsoft.Office.Interop.Outlook.NameSpace   ns  = app.GetNamespace("MAPI");
            Outlook.MAPIFolder f = ns.GetDefaultFolder(OlDefaultFolders.olFolderInbox);
            //        Thread.Sleep(5000);
            Outlook.AppointmentItem newAppointment =
                (Outlook.AppointmentItem)
                app.CreateItem(Outlook.OlItemType.olAppointmentItem);
            //  string org = newAppointment.Organizer;
            //   newAppointment.Resources = "Missionator";
            newAppointment.Companies = "Missionator";
            newAppointment.Start     = m.DueDate.Date;
            newAppointment.End       = m.DueDate.Date;
            //  newAppointment.Location = "ConferenceRoom #2345";


            newAppointment.RTFBody = System.Text.Encoding.UTF8.GetBytes(@"
{\rtf1\ansi\deff0 {\fonttbl {\f0 Arial;}}
{\colortbl;\red0\green0\blue0;\red255\green0\blue0;\red122\green122\blue192;}
\qr\b\fs48" + GetRtfUnicodeEscapedString(m.Title) + @"\b0\line\line

\cf2\fs36
" + DateTime.Now.ToShortDateString() + @":\line
\cf1\fs24
" + GetRtfUnicodeEscapedString(m.Body.Replace("\n", @"\line")) + @"\line\line
\fs20\cf3 " + GetRtfUnicodeEscapedString("נקבע מועד הגשה ל: ") + m.DueDate.ToShortDateString().Replace('/', '.') + @"\cf1\fs24\line
}
");



            //newAppointment.RTFBody = @"{\rtf1\ansi\b "+m.Title+@"\b0.}";
            //newAppointment.RTFBody += "<h2><b>" + DateTime.Now.ToShortDateString() + ":</b></h2><br/>";
            //newAppointment.RTFBody += "<body>" + m.Body + "</body>";
            //   newAppointment.RTFBody.Replace("\n", "<br/>");

            newAppointment.AllDayEvent = true;
            newAppointment.Subject     = m.Title;
            string resourceBuilder = "";

            foreach (string recipient in m.Recipients)
            {
                newAppointment.Recipients.Add(recipient);
                if (m.Recipients.IndexOf(recipient) > 0)
                {
                    resourceBuilder += ",";
                }
                resourceBuilder += recipient;
            }
            newAppointment.Mileage = resourceBuilder;
            Outlook.Recipients sentTo = newAppointment.Recipients;
            //Outlook.Recipient sentInvite = null;
            //sentInvite = sentTo.Add("Holly Holt");
            //sentInvite.Type = (int)Outlook.OlMeetingRecipientType
            //    .olRequired;
            //sentInvite = sentTo.Add("David Junca ");
            //sentInvite.Type = (int)Outlook.OlMeetingRecipientType
            //    .olOptional;
            //sentTo.ResolveAll();
            newAppointment.Save();
            //   newAppointment.Display(true);
            //     }
            //    catch (Exception ex)
            //{
            //    MessageBox.Show("The following error occurred: " + ex.Message);
            //    return false;
            //}
            return(true);
        }
예제 #9
0
        public bool UpdateMissionDate(AppointmentItem appointment, Mission m, string update)
        {
            if (update == "" && m.DueDate == appointment.Start)
            {
                return(false);
            }
            Microsoft.Office.Interop.Outlook.Application app = new Microsoft.Office.Interop.Outlook.Application();
            Microsoft.Office.Interop.Outlook.NameSpace   ns  = app.GetNamespace("MAPI");
            Outlook.MAPIFolder f        = ns.GetDefaultFolder(OlDefaultFolders.olFolderInbox);
            byte[]             origText = (byte[])appointment.RTFBody;

            string s = System.Text.Encoding.UTF8.GetString(origText);

            s = s.Remove(s.LastIndexOf('}'), 1);


            s += @"\line\fs36\cf2 " + DateTime.Now.ToString();
            if (update != "")
            {
                s += @" \line\cf1\fs24 " + GetRtfUnicodeEscapedString(update.Replace("\n", @"\line"));
            }
            if (m.DueDate != appointment.Start)
            {
                s += @" \line\line\fs20\cf3 " + GetRtfUnicodeEscapedString("נקבע מועד הגשה חדש: ") + m.DueDate.ToShortDateString().Replace('/', '.');
            }
            s += @"\line}";


            appointment.Start = m.DueDate;
            appointment.End   = m.DueDate;
            //  System.Buffer.BlockCopy(origText, 0, merged, 0, origText.Length);
            // System.Buffer.BlockCopy(newText, 0, merged, origText.Length, newText.Length);
            appointment.RTFBody   = System.Text.Encoding.UTF8.GetBytes(s);
            appointment.Companies = "Missionator";
            string resourceBuilder = "";

            foreach (string recipient in m.Recipients)
            {
                appointment.Recipients.Add(recipient);
                if (m.Recipients.IndexOf(recipient) > 0)
                {
                    resourceBuilder += ",";
                }
                resourceBuilder += recipient;
            }
            appointment.Mileage = resourceBuilder;
            Outlook.Recipients sentTo = appointment.Recipients;
            appointment.Save();



            //Outlook.AppointmentItem newAppointment =
            //      (Outlook.AppointmentItem)
            //  app.CreateItem(Outlook.OlItemType.olAppointmentItem);
            ////  string org = newAppointment.Organizer;
            ////   newAppointment.Resources = "Missionator";
            //newAppointment.Companies = "Missionator";
            //newAppointment.Start = m.DueDate.Date;
            //newAppointment.End = m.DueDate.Date;
            ////  newAppointment.Location = "ConferenceRoom #2345";


            //newAppointment.RTFBody =  System.Text.Encoding.UTF8.GetBytes(s);;

            //newAppointment.AllDayEvent = true;
            //newAppointment.Subject = m.Title;
            //string resourceBuilder = "";
            //foreach (string recipient in m.Recipients)
            //{
            //    newAppointment.Recipients.Add(recipient);
            //    if (m.Recipients.IndexOf(recipient) > 0)
            //        resourceBuilder += ",";
            //    resourceBuilder += recipient;
            //}
            //newAppointment.Resources = resourceBuilder;
            //Outlook.Recipients sentTo = newAppointment.Recipients;

            //newAppointment.Save();

            return(true);
        }
        //Big Brother of ReadSingleMail() - Deals with email batches - Runs only once when Outlook is first launched
        static void ReadMail()
        {
            //Set up OCR
            OnenoteOcrEngine ocr = new OnenoteOcrEngine();

            string bodyText;
            string mydocpath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

            //Get unread emails from Inbox
            Microsoft.Office.Interop.Outlook.Application app = null;
            Microsoft.Office.Interop.Outlook._NameSpace ns = null;
            Microsoft.Office.Interop.Outlook.MAPIFolder inboxFolder = null;
            app = new Microsoft.Office.Interop.Outlook.Application();
            ns = app.GetNamespace("MAPI");
            inboxFolder = ns.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
            Outlook.Items unreadItems = inboxFolder.Items.Restrict("[Unread]=true");
            int max_runs;
            //Go through each Unread email
            if (unreadItems.Count > 10) { max_runs = 10; }
            else max_runs = unreadItems.Count;

            for (int counter = 1; counter <= max_runs; counter++)
            {
                //Reinitialize Data array
                for (int index = 0; index <= 8; index++)
                {
                    data[index] = "";
                }
                skipTextReader = false;

                dynamic item = unreadItems[counter];
                StringBuilder sb = new StringBuilder();

                if (ReadImageFromEmail(item) == 1) // If email has an attachment, read the attachment
                {
                    Image imageToParse = Image.FromFile(@"C:\TestFileSave\" + item.Attachments[1].FileName);
                    bodyText = ocr.Recognize(imageToParse);
                    //MessageBox.Show(bodyText);
                    if (bodyText != null)
                    {
                        bodyText = bodyText.Replace(" ", ";");
                        bodyText = bodyText.Replace(";;", ";");
                        bodyText = bodyText.Replace(",", "");
                        bodyText = bodyText.Replace("|", ";");
                        skipTextReader = true; //Bool variable if email has image signature

                        data = parseOCRSignature(bodyText);

                    }
                    else
                    {
                        break;
                    }
                }

                else //If no attachment, extract email body
                {
                    if (item != null)
                    {
                        bodyText = item.Body;
                    }
                    else
                    {
                        continue;
                    }
                    sb.Append(bodyText);
                }

                if (skipTextReader == false) //If no image signature, parse email body
                {
                    File.AppendAllText(mydocpath + @"\MailFile.txt", sb.ToString());
                    sb.Remove(0, bodyText.Length);
                    string signature = extractSignature().Replace(";;", ";"); //Extract signature block
                    //IF EMBEDDED IMAGE SIGNATURE FOUND
                    if (((signature.ToLower()).Contains(".png") || (signature.ToLower()).Contains(".gif") || (signature.ToLower()).Contains(".jpg")) && signature.Length<20)
                    {
                        //MessageBox.Show(signature);
                        Image imageToParse = Image.FromFile(@"C:\TestFileSave\" + signature);
                        bodyText = ocr.Recognize(imageToParse);
                        //MessageBox.Show(bodyText);
                        if (bodyText != null)
                        {
                            bodyText = bodyText.Replace(" ", ";");
                            bodyText = bodyText.Replace(";;", ";");
                            bodyText = bodyText.Replace(",", "");
                            bodyText = bodyText.Replace("|", ";");
                            skipTextReader = true; //Bool variable if email has image signature
                            data = parseOCRSignature(bodyText);
                        }
                    }
                    else
                    {
                        data = parseImageSignature(signature); //Parse signature block
                    }
                }

                //Send data to database
                //Get Sender Email Address
                string strEmailSenderEmailId = Convert.ToString(item.SenderEmailAddress);

                //Set up DB connections
                SqlConnection connection = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Prashanth\Desktop\CAPSTONE JPMORGAN\OutlookAddIn1\OutlookContacts.mdf;Integrated Security=True;User Instance=True");
                SqlCommand command = new SqlCommand();
                SqlDataReader dataReader;
                command.Connection = connection;
                connection.Open();

                command.CommandText = "select * from New_Contacts where Email_ID = '" + strEmailSenderEmailId + "'";
                dataReader = command.ExecuteReader();

                //Check if contact exists already
                if (dataReader.HasRows == false)
                {
                    command.CommandText = "insert into New_Contacts VALUES('" + data[0] + "' , '" + data[1] + "' , '" + data[2] + "' , '" + data[3] + "' , '" + data[4] + "' , '" + data[5] + "' , '" + data[6] + "' , '" + data[7] + "' , '" + data[8] + "' , '" + strEmailSenderEmailId + "' , '" + data[9] + "')";
                    dataReader.Close();
                    command.ExecuteNonQuery();
                }
                //If it does, update and overwrite past data
                else
                {
                    UpdateSelectFields(data[2], data[4], data[7], data[5], data[6], data[8] , data[9], strEmailSenderEmailId);

                }

            }

            System.IO.File.Delete(mydocpath + @"\MailFile.txt");
            timer.Stop();
            time_elapsed = time_elapsed + timer.Elapsed.TotalSeconds;
            ocr.Dispose();

            MessageBox.Show("SigX took " + (time_elapsed).ToString() + " seconds for " + unreadItems.Count +
                "emails!");
            //connection.Close();
        }