Exemplo n.º 1
0
 public void showAddress(string searchName, Outlook.AddressEntry address, int flag)
 {
     if (address != null)
     {
         // 邮件地址
         if (address.AddressEntryUserType == Outlook.OlAddressEntryUserType.olExchangeUserAddressEntry)  // 普通地址
         {
             // 普通地址的 searchName 中缺少Email地址 需要另外获取
             this.showSingle(this.i18n[this.lang]["mailAddress"] + ": " + searchName + " " + address.GetExchangeUser().PrimarySmtpAddress, flag);
         }
         else if (address.AddressEntryUserType == Outlook.OlAddressEntryUserType.olOutlookContactAddressEntry) // 存入联系人中的地址
         {
             // 存入联系人中的地址的 searchName 中包含了Email地址 无要另外获取
             this.showSingle(this.i18n[this.lang]["mailAddress"] + ": " + searchName, flag);
         }
         // 组邮件地址
         else if (address.AddressEntryUserType == Outlook.OlAddressEntryUserType.olExchangeDistributionListAddressEntry) // 普通组地址
         {
             // 普通组地址的 searchName 为组名 Email地址可通过Outlook ExchangeDistributionList 对象获取
             Outlook.ExchangeDistributionList disList = address.GetExchangeDistributionList();
             this.showMuilt(this.i18n[this.lang]["groupMailAddress"] + ": " + searchName + " " + disList.PrimarySmtpAddress, flag);
             this.addAddressNativeGroupList(disList);
         }
         else if (address.AddressEntryUserType == Outlook.OlAddressEntryUserType.olOutlookDistributionListAddressEntry) // 自建组地址
         {
             // 自建组地址的 searchName 为组名 且无Email地址 直接仅显示组名
             this.showMuilt(this.i18n[this.lang]["groupMailAddress"] + ": " + searchName, flag);
             this.addAddressSelfBuildGroupList(address, searchName);
         }
     }
     else
     {
         this.showSingle(searchName, 0);
     }
 }
Exemplo n.º 2
0
 public void GetDistributionListMembers(string addlistname, DataGridView dgv)
 {
     Outlook.SelectNamesDialog snd =
         app.Session.GetSelectNamesDialog();
     Outlook.AddressLists addrLists =
         app.Session.AddressLists;
     foreach (Outlook.AddressList addrList in addrLists)
     {
         if (addrList.Name == addlistname)
         {
             snd.InitialAddressList = addrList;
             break;
         }
     }
     snd.NumberOfRecipientSelectors = Outlook.OlRecipientSelectors.olShowTo;
     snd.ToLabel = "D/L";
     snd.ShowOnlyInitialAddressList = true;
     snd.AllowMultipleSelection     = false;
     snd.Display();
     if (snd.Recipients.Count > 0)
     {
         Outlook.AddressEntry addrEntry =
             snd.Recipients[1].AddressEntry;
         if (addrEntry.AddressEntryUserType ==
             Outlook.OlAddressEntryUserType.
             olExchangeDistributionListAddressEntry)
         {
             Outlook.ExchangeDistributionList exchDL =
                 addrEntry.GetExchangeDistributionList();
             Outlook.AddressEntries addrEntries =
                 exchDL.GetExchangeDistributionListMembers();
             if (addrEntries != null)
             {
                 foreach (Outlook.AddressEntry exchDLMember
                          in addrEntries)
                 {
                     DataGridViewRow dgvr = new DataGridViewRow();
                     dgvr.CreateCells(dgv);
                     dgvr.Cells[0].Value = exchDLMember.Name;
                     dgvr.Cells[1].Value = exchDLMember.Address;
                     dgv.Rows.Add(dgvr);
                     // Debug.WriteLine(exchDLMember.Name);
                 }
             }
         }
     }
 }
Exemplo n.º 3
0
        public static void DisplayGlobalAddressList()
        {
            DataTable table = new DataTable();

            table.Columns.Add("Name", typeof(string));
            table.Columns.Add("Company", typeof(string));
            table.Columns.Add("Address", typeof(string));

            Outlook.Application outlook = new Outlook.Application();

            Outlook.AddressList gal = outlook.Session.GetGlobalAddressList();

            if (gal != null)
            {
                for (int i = 1; i < gal.AddressEntries.Count - 1; i++)
                {
                    try
                    {
                        Outlook.AddressEntry addressEntry = gal.AddressEntries[i];

                        if (addressEntry.AddressEntryUserType == Outlook.OlAddressEntryUserType.olExchangeUserAddressEntry || addressEntry.AddressEntryUserType == Outlook.OlAddressEntryUserType.olExchangeRemoteUserAddressEntry)
                        {
                            Outlook.ExchangeUser exUser = addressEntry.GetExchangeUser();
                            Debug.WriteLine(exUser.Name + "    " + exUser.CompanyName);
                            table.Rows.Add(exUser.Name, exUser.CompanyName, exUser.PrimarySmtpAddress);
                        }

                        if (addressEntry.AddressEntryUserType == Outlook.OlAddressEntryUserType.olExchangeDistributionListAddressEntry)
                        {
                            Outlook.ExchangeDistributionList exList = addressEntry.GetExchangeDistributionList();
                            Debug.WriteLine(exList.Name + "   " + exList.PrimarySmtpAddress);
                            table.Rows.Add(exList.Name, "", "");
                        }
                    }
                    catch
                    {
                        continue;
                    }
                }
            }

            ExportCsvUtil.ExportCsv(table, "", "");
        }
Exemplo n.º 4
0
        private void LoadContactsList()
        {
            Outlook.Application outlookApp = new Microsoft.Office.Interop.Outlook.Application();

            Outlook.Folder contactsFolder = outlookApp.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olPublicFoldersAllPublicFolders) as Outlook.Folder;

            Outlook.Folder currentFolder = outlookApp.ActiveExplorer().CurrentFolder as Outlook.Folder;
            Outlook.Store  currentStore  = currentFolder.Store;

            Outlook.AddressList    addressList = this.GetGlobalAddressList(outlookApp, currentStore);
            Outlook.AddressEntries entries     = addressList.AddressEntries;

            this._contactsList = new List <Contact>();

            foreach (Outlook.AddressEntry entry in entries)
            {
                Outlook.ExchangeDistributionList distList = entry.GetExchangeDistributionList();
                Outlook.ExchangeUser             user     = entry.GetExchangeUser();
                Outlook.ContactItem contact = entry.GetContact();

                if (distList != null)
                {
                    this._contactsList.Add(new Contact(distList.Name, distList.PrimarySmtpAddress));
                }

                if (contact != null)
                {
                    this._contactsList.Add(new Contact(contact.FirstName + " " + contact.LastName, contact.IMAddress));
                }

                if (user != null)
                {
                    if (user.FirstName == null && user.LastName == null)
                    {
                        this._contactsList.Add(new Contact(user.Name, user.PrimarySmtpAddress));
                    }
                    else
                    {
                        this._contactsList.Add(new Contact(user.FirstName + " " + user.LastName, user.PrimarySmtpAddress));
                    }
                }
            }
        }
Exemplo n.º 5
0
        private void EnumerateDL(Outlook.AddressEntry dl, string prefix = "")
        {
            if (AlreadyEnumeratedDL(dl))
            {
                System.Diagnostics.Debug.WriteLine(prefix + dl.Name + "> <skipping nested dl>");
            }
            else
            {
                _seenDLs.Add(dl);

                Outlook.ExchangeDistributionList exchDL      = dl.GetExchangeDistributionList();
                Outlook.AddressEntries           addrEntries = exchDL.GetExchangeDistributionListMembers();

                if (addrEntries != null)
                {
                    foreach (Outlook.AddressEntry exchDLMember in addrEntries)
                    {
                        if (exchDLMember.AddressEntryUserType == Outlook.OlAddressEntryUserType.olExchangeDistributionListAddressEntry)
                        {
                            EnumerateDL(exchDLMember, prefix + dl.Name + " > ");
                        }
                        else
                        {
                            var entry = prefix + dl.Name + " > " + exchDLMember.Name;
                            System.Diagnostics.Debug.WriteLine(entry);
                            lstMembers.Items.Add(entry);

                            if (exchDLMember.Address == _currentUser.Address)
                            {
                                MessageBox.Show("Found You!\n\n" + entry);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 6
0
        private void ProcessEmailAddresses(TaskObject task, Microsoft.Office.Interop.Outlook.MailItem mail)
        {
            try
            {
                //Add Sender to task
                if (mail.SenderEmailAddress != null & mail.SenderEmailAddress != "")
                {
                    if (mail.SenderEmailType == "EX")
                    {
                        //Issue a reply on the mail message to create a recipient object that is the sender address.
                        Outlook._MailItem Temp = ((Outlook._MailItem)mail).Reply();

                        //Use the recipient object to access the smtp address of the exchange user
                        CreateEmailAddress(task, Temp.Recipients[1].AddressEntry.GetExchangeUser().PrimarySmtpAddress);
                        Temp.Delete();
                    }
                    else
                    {
                        //Use the address
                        CreateEmailAddress(task, mail.SenderEmailAddress);
                    }
                }
                //Add recipients (Employees and Suppliers) to task
                foreach (Microsoft.Office.Interop.Outlook.Recipient recipient in mail.Recipients)
                {
                    if (recipient.Address != "" & recipient.Address != null)
                    {
                        if (recipient.AddressEntry.AddressEntryUserType == Outlook.OlAddressEntryUserType.olExchangeUserAddressEntry ||
                            recipient.AddressEntry.AddressEntryUserType == Outlook.OlAddressEntryUserType.olExchangeRemoteUserAddressEntry)
                        {
                            //Use the ExchangeUser object PrimarySMTPAddress
                            Outlook.ExchangeUser exchUser = recipient.AddressEntry.GetExchangeUser();
                            if (exchUser != null)
                            {
                                CreateEmailAddress(task, exchUser.PrimarySmtpAddress);
                            }
                        }
                        else if (recipient.AddressEntry.AddressEntryUserType == Outlook.OlAddressEntryUserType.olExchangeDistributionListAddressEntry)
                        {
                            //Use the ExchangDistributionList object PrimarySMTPAddress
                            Outlook.ExchangeDistributionList exchDL = recipient.AddressEntry.GetExchangeDistributionList();

                            if (exchDL != null)
                            {
                                CreateEmailAddress(task, exchDL.PrimarySmtpAddress);
                            }
                        }
                        else
                        {
                            //Use the address
                            CreateEmailAddress(task, recipient.Address);
                        }
                    }
                }
            }
            catch (System.Exception exception1)
            {
                System.Exception innerException = exception1;
                throw new System.Exception(MethodBase.GetCurrentMethod().Name, innerException);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// 送信先の表示名と表示名とメールアドレスを対応させる。(Outlookの仕様上、表示名にメールアドレスが含まれない事がある。)
        /// </summary>
        /// <param name="mail"></param>
        private void MakeDisplayNameAndRecipient(Outlook._MailItem mail)
        {
            //TODO Temporary processing. It will be improved.
            //暫定的にこのメソッドを複数回実行する可能性があるため、実行のたびに以下の3つは初期化する。
            _toDisplayNameAndRecipient.Clear();
            _ccDisplayNameAndRecipient.Clear();
            _bccDisplayNameAndRecipient.Clear();

            foreach (Outlook.Recipient recip in mail.Recipients)
            {
                // Exchangeの連絡先に登録された情報を取得。
                Outlook.ExchangeUser exchangeUser = null;
                try
                {
                    exchangeUser = recip.AddressEntry.GetExchangeUser();
                }
                catch (Exception)
                {
                    //Do Nothing.
                }

                // Exchangeの配布リスト(ML)として登録された情報を取得。
                Outlook.ExchangeDistributionList exchangeDistributionList = null;
                try
                {
                    exchangeDistributionList = recip.AddressEntry.GetExchangeDistributionList();
                }
                catch (Exception)
                {
                    //Do Nothing.
                }

                // ローカルの連絡先に登録された情報を取得。
                Outlook.ContactItem registeredUser = null;
                try
                {
                    registeredUser = recip.AddressEntry.GetContact();
                }
                catch (Exception)
                {
                    //Do Nothing.
                }

                //宛先メールアドレスを取得
                string mailAddress = recip.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x39FE001E").ToString() ?? Resources.FailedToGetInformation;

                // 登録されたメールアドレスの場合、登録名のみが表示されるため、メールアドレスと共に表示されるよう表示用テキストを生成。
                var nameAndMailAddress = exchangeUser != null
                    ? exchangeUser.Name + $@" ({mailAddress})"
                    : exchangeDistributionList != null
                        ? exchangeDistributionList.Name + $@" ({mailAddress})"
                        : registeredUser != null
                            ? registeredUser.FullName + $@" ({mailAddress})"
                            : mailAddress ?? Resources.FailedToGetInformation;

                //ケースによってメールアドレスのみを正しく取得できない恐れがあるため、その場合は、表示名称をメールアドレスとして登録する。
                if (!mailAddress.Contains("@"))
                {
                    mailAddress = nameAndMailAddress;
                }

                _displayNameAndRecipient[mailAddress] = nameAndMailAddress;

                //TODO Temporary processing. It will be improved.
                //名称を差出人とメールアドレスの紐づけをTo/CC/BCCそれぞれに格納
                switch (recip.Type)
                {
                case 1:
                    _toDisplayNameAndRecipient[mailAddress] = nameAndMailAddress;
                    break;

                case 2:
                    _ccDisplayNameAndRecipient[mailAddress] = nameAndMailAddress;
                    break;

                case 3:
                    _bccDisplayNameAndRecipient[mailAddress] = nameAndMailAddress;
                    break;

                default:
                    break;
                }
            }
        }
Exemplo n.º 8
0
 public void addAddressNativeGroupList(Outlook.ExchangeDistributionList disList) // 普通组邮件成员list添加到addressList区存储
 {
     Outlook.AddressEntries addressEntries = disList.GetExchangeDistributionListMembers();
     this.addressList.Add(addressEntries);
 }