コード例 #1
0
        void cmdButton_Click(Office.CommandBarButton Ctrl, ref bool CancelDefault)
        {
            try
            {
                if (Application.ActiveExplorer().Selection.Count > 1)
                {
                    MessageBox.Show("Please only select a single email.");
                    return;
                }

                Outlook.MailItem mail = Application.ActiveExplorer().Selection[1] as Outlook.MailItem;

                SafeMailItem safeMail = new SafeMailItem();

                safeMail.Item = mail;

                string add = safeMail.Sender.SMTPAddress;

                if (!String.IsNullOrEmpty(add))
                {
                    Regex regex = new Regex("^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}$", RegexOptions.IgnoreCase);

                    if (regex.IsMatch(add))
                    {
                        contactId = EmailSearch(add,"Contacts");
                    }
                    else
                    {
                        return;
                    }
                }
                else
                {
                    return;
                }

                if (contactId == null)
                {
                    Form frmCreate = new CreateAccountContact(mail);
                    frmCreate.FormClosed += new FormClosedEventHandler(frmCreate_FormClosed);
                    frmCreate.ShowDialog();
                }
                else
                {
                    Form frmContactFound = new ContactFound(contactId, safeMail);
                    frmContactFound.ShowDialog();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
コード例 #2
0
        void frmCreate_FormClosed(object sender, FormClosedEventArgs e)
        {
            CreateAccountContact frm = (CreateAccountContact)sender;

            Outlook.MailItem mail = Application.ActiveExplorer().Selection[1] as Outlook.MailItem;

            SafeMailItem safeMail = new SafeMailItem();

            safeMail.Item = mail;

            string add = safeMail.Sender.SMTPAddress;

            contactId = EmailSearch(add);

            if ((frm.DialogResult == DialogResult.Yes) & (!String.IsNullOrEmpty(contactId)))
            {
                Form frmContactFound = new ContactFound(contactId, safeMail);
                frmContactFound.ShowDialog();
            }
        }