Exemplo n.º 1
0
        private void FindContactEmailByName(string firstName, string lastName)
        {
            Outlook.NameSpace  outlookNameSpace = this.Application.GetNamespace("MAPI");
            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)
                {
                    contact.Display(true);
                }
                else
                {
                    MessageBox.Show("The contact information was not found.");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 2
0
 private void AddDefaultContact()
 {
     Outlook.ContactItem newContact = (Outlook.ContactItem)
                                      this.Application.CreateItem(Outlook.OlItemType.olContactItem);
     try
     {
         newContact.FirstName              = "Chris";
         newContact.LastName               = "Berry";
         newContact.Email1Address          = "*****@*****.**";
         newContact.CustomerID             = "123456";
         newContact.PrimaryTelephoneNumber = "(425)555-0111";
         newContact.MailingAddressStreet   = "123 Main St.";
         newContact.MailingAddressCity     = "Redmond";
         var mailUserProperties = newContact.UserProperties;
         // Where 1 is OlFormatText (introduced in Outlook 2007)
         newContact.UserProperties.Add("CaseID", Outlook.OlUserPropertyType.olText, true, 1);
         newContact.UserProperties["CaseID"].Value = "1234567890123456";
         //newContact.UserProperties["Case Id"].Value = "1234567890123456";
         newContact.MailingAddressState = "WA";
         newContact.Save();
         newContact.Display(true);
     }
     catch
     {
         MessageBox.Show("The new contact was not saved.");
     }
 }
 /// <summary>
 /// Open the task
 /// </summary>
 /// <param name="sender">Sender</param>
 /// <param name="e">EventArgs</param>
 private void lstTasks_DoubleClick(object sender, EventArgs e)
 {
     if (this.lstTasks.SelectedIndices.Count != 0)
     {
         OLTaskItem task = this.lstTasks.SelectedItems[0].Tag as OLTaskItem;
         if (task != null)
         {
             if (task.OriginalItem is Outlook.MailItem)
             {
                 Outlook.MailItem mail = task.OriginalItem as Outlook.MailItem;
                 mail.Display(true);
             }
             else if (task.OriginalItem is Outlook.ContactItem)
             {
                 Outlook.ContactItem contact = task.OriginalItem as Outlook.ContactItem;
                 contact.Display(true);
             }
             else if (task.OriginalItem is Outlook.TaskItem)
             {
                 Outlook.TaskItem t = task.OriginalItem as Outlook.TaskItem;
                 t.Display(true);
             }
             else
             {
                 // Do nothing
             }
             // At the end, synchronously "refresh" tasks in case they have changed
             this.RetrieveTasks();
         }
     }
 }
Exemplo n.º 4
0
        private void CurrentExplorer_Event()
        {
            Outlook.MAPIFolder selectedFolder =
                this.Application.ActiveExplorer().CurrentFolder;
            String expMessage = "Your current folder is "
                                + selectedFolder.Name + ".\n";
            String itemMessage = "Item is unknown.";

            try
            {
                if (this.Application.ActiveExplorer().Selection.Count > 0)
                {
                    Object selObject = this.Application.ActiveExplorer().Selection[1];
                    if (selObject is Outlook.MailItem)
                    {
                        Outlook.MailItem mailItem =
                            (selObject as Outlook.MailItem);
                        itemMessage = "The item is an e-mail message." +
                                      " The subject is " + mailItem.Subject + ".";
                        mailItem.Display(false);
                    }
                    else if (selObject is Outlook.ContactItem)
                    {
                        Outlook.ContactItem contactItem =
                            (selObject as Outlook.ContactItem);
                        itemMessage = "The item is a contact." +
                                      " The full name is " + contactItem.Subject + ".";
                        contactItem.Display(false);
                    }
                    else if (selObject is Outlook.AppointmentItem)
                    {
                        Outlook.AppointmentItem apptItem =
                            (selObject as Outlook.AppointmentItem);
                        itemMessage = "The item is an appointment." +
                                      " The subject is " + apptItem.Subject + ".";
                    }
                    else if (selObject is Outlook.TaskItem)
                    {
                        Outlook.TaskItem taskItem =
                            (selObject as Outlook.TaskItem);
                        itemMessage = "The item is a task. The body is "
                                      + taskItem.Body + ".";
                    }
                    else if (selObject is Outlook.MeetingItem)
                    {
                        Outlook.MeetingItem meetingItem =
                            (selObject as Outlook.MeetingItem);
                        itemMessage = "The item is a meeting item. " +
                                      "The subject is " + meetingItem.Subject + ".";
                    }
                }
                expMessage = expMessage + itemMessage;
            }
            catch (Exception ex)
            {
                expMessage = ex.Message;
            }
            MessageBox.Show(expMessage);
        }
Exemplo n.º 5
0
        //gavdcodeend 06

        //gavdcodebegin 07
        private void btnAddContact_Click(object sender, RibbonControlEventArgs e)
        {
            Outlook.Application myApplication = Globals.ThisAddIn.Application;

            Outlook.ContactItem newContact = (Outlook.ContactItem)
                                             myApplication.CreateItem(Outlook.OlItemType.olContactItem);

            newContact.FirstName              = "He Is";
            newContact.LastName               = "Somebody";
            newContact.Email1Address          = "*****@*****.**";
            newContact.PrimaryTelephoneNumber = "(123)4567890";
            newContact.MailingAddressStreet   = "Here 123";
            newContact.MailingAddressCity     = "There";
            newContact.Save();
            newContact.Display(true);
        }
Exemplo n.º 6
0
        //gavdcodeend 05

        //gavdcodebegin 06
        private void btnFindContact_Click(object sender, RibbonControlEventArgs e)
        {
            Outlook.Application myApplication = Globals.ThisAddIn.Application;

            Outlook.NameSpace  outlookNameSpace = myApplication.GetNamespace("MAPI");
            Outlook.MAPIFolder myContactsFolder = outlookNameSpace.GetDefaultFolder(
                Outlook.OlDefaultFolders.olFolderContacts);

            Outlook.Items       myContactItems = myContactsFolder.Items;
            Outlook.ContactItem myContact      = (Outlook.ContactItem)myContactItems.
                                                 Find("[FirstName]='a' and [LastName]='b'");
            if (myContact != null)
            {
                myContact.Display(true);
            }
            else
            {
                MessageBox.Show("Contact not found");
            }
        }
Exemplo n.º 7
0
 //<Snippet1>
 private void AddContact()
 {
     Outlook.ContactItem newContact = (Outlook.ContactItem)
                                      this.Application.CreateItem(Outlook.OlItemType.olContactItem);
     try
     {
         newContact.FirstName              = "Jo";
         newContact.LastName               = "Berry";
         newContact.Email1Address          = "*****@*****.**";
         newContact.CustomerID             = "123456";
         newContact.PrimaryTelephoneNumber = "(425)555-0111";
         newContact.MailingAddressStreet   = "123 Main St.";
         newContact.MailingAddressCity     = "Redmond";
         newContact.MailingAddressState    = "WA";
         newContact.Save();
         newContact.Display(true);
     }
     catch
     {
         MessageBox.Show("The new contact was not saved.");
     }
 }
        public override void ShowContactForm(IContactItem contact)
        {
            try
            {
                ToggleSecurityWarning(true);
                Microsoft.Office.Interop.Outlook.ContactItem item = contact.BaseContact as Microsoft.Office.Interop.Outlook.ContactItem;

                if (item != null)
                {
                    item.Display(true);
                    contact.SyncValuesFromBase();
                }
            }
            catch (System.Exception ex)
            {
                FireContactManagerFailureEvent(ex);
            }
            finally
            {
                ToggleSecurityWarning(false);
            }
        }
Exemplo n.º 9
0
        private void ButtonAddContactJunk_Click(object sender, RibbonControlEventArgs e)
        {
            if (Globals.ThisAddIn.Application.ActiveExplorer().Selection.Count > 0)
            {
                Object selectedObject = Globals.ThisAddIn.Application.ActiveExplorer().Selection[1];
                if (selectedObject is Outlook.MailItem email)
                {
                    if (email is object)
                    {
                        Outlook.MAPIFolder  contactsFolder = null;
                        Outlook.Items       items          = null;
                        Outlook.ContactItem contact        = null;
                        try
                        {
                            InTouch.ShowInTouchSettings = true;
                            contactsFolder = Globals.ThisAddIn.Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts).Folders["Junk Contacts"];
                            items          = contactsFolder.Items;
                            contact        = items.Add(Outlook.OlItemType.olContactItem) as Outlook.ContactItem;

                            Clipboard.SetDataObject(email.Sender.Name);

                            contact.FullName      = email.Sender.Name;
                            contact.Email1Address = email.Sender.Address;

                            string data;
                            contact.UserProperties.Add("InTouchContact", Outlook.OlUserPropertyType.olText);
                            data  = "|";
                            data += "|";
                            data += "3|";
                            data += "3|";
                            data += "0|";
                            data += "True|";
                            contact.UserProperties["InTouchContact"].Value = data;

                            contact.Save();
                            contact.Display(true);

                            lastEntryID = "";
                            Parallel.Invoke(() => { CheckEmailSender(); });
                        }
                        catch (Exception ex)
                        {
                            Log.Error(ex);
                            InTouch.ShowInTouchSettings = false;
                        }
                        finally
                        {
                            if (contact != null)
                            {
                                Marshal.ReleaseComObject(contact);
                            }
                            if (items != null)
                            {
                                Marshal.ReleaseComObject(items);
                            }
                            if (contactsFolder != null)
                            {
                                Marshal.ReleaseComObject(contactsFolder);
                            }
                        }
                    }
                    if (email is object)
                    {
                        Marshal.ReleaseComObject(email);
                    }
                }
                if (selectedObject is object)
                {
                    Marshal.ReleaseComObject(selectedObject);
                }
            }
        }
Exemplo n.º 10
0
        private void CurrentExplorer_SelectionChange()
        {
            Outlook.MAPIFolder selectedFolder = this.Application.ActiveExplorer().CurrentFolder;
            String             expMessage     = "Your current folder is " + selectedFolder.Name + ".\n";
            String             itemMessage    = "Item is unknown.";


            if ((!currentExplorer.CurrentFolder.FullFolderPath.Contains("*****@*****.**")) && (!currentExplorer.CurrentFolder.FullFolderPath.Contains("gslockwood")))
            {
                return;
            }

            try
            {
                if (this.Application.ActiveExplorer().Selection.Count > 0)
                {
                    Object selObject = this.Application.ActiveExplorer().Selection[1];
                    if (selObject is Outlook.MailItem)
                    {
                        Outlook.MailItem mailItem = (selObject as Outlook.MailItem);

                        if (mailItem.EntryID == lastEntryID)
                        {
                            return;
                        }
                        lastEntryID = mailItem.EntryID;

                        if (jobListTaskPane != null)
                        {
                            jobListTaskPane.Clear();
                        }

                        //ProcessEmailEx( mailItem );
                        ProcessMailItem(mailItem);
                        //
                    }
                    else if (selObject is Outlook.ContactItem)
                    {
                        Outlook.ContactItem contactItem =
                            (selObject as Outlook.ContactItem);
                        itemMessage = "The item is a contact." +
                                      " The full name is " + contactItem.Subject + ".";
                        contactItem.Display(false);
                    }
                    else if (selObject is Outlook.AppointmentItem)
                    {
                        Outlook.AppointmentItem apptItem =
                            (selObject as Outlook.AppointmentItem);
                        itemMessage = "The item is an appointment." +
                                      " The subject is " + apptItem.Subject + ".";
                    }
                    else if (selObject is Outlook.TaskItem)
                    {
                        Outlook.TaskItem taskItem =
                            (selObject as Outlook.TaskItem);
                        itemMessage = "The item is a task. The body is "
                                      + taskItem.Body + ".";
                    }
                    else if (selObject is Outlook.MeetingItem)
                    {
                        Outlook.MeetingItem meetingItem =
                            (selObject as Outlook.MeetingItem);
                        itemMessage = "The item is a meeting item. " +
                                      "The subject is " + meetingItem.Subject + ".";
                    }
                }
                expMessage = expMessage + itemMessage;
            }
            catch (Exception ex)
            {
                expMessage = ex.Message;
            }

            //MessageBox.Show(expMessage);
        }