Esempio n. 1
0
        public String GetCurrentUserInfos()
        {
            String wComputername = System.Environment.MachineName + " (" + System.Environment.OSVersion.ToString() + ")";
            String wUsername     = System.Environment.UserDomainName + "\\" + System.Environment.UserName;

            string str = Resources.EmailBody_PossiblyUsefulIInformation;


            Outlook.AddressEntry addrEntry = Globals.ThisAddIn.Application.Session.CurrentUser.AddressEntry;
            if (addrEntry.Type == "EX")
            {
                Outlook.ExchangeUser currentUser =
                    Globals.ThisAddIn.Application.Session.CurrentUser.
                    AddressEntry.GetExchangeUser();
                if (currentUser != null)
                {
                    str += "\n" + Resources.EmailBody_Username + currentUser.Name;
                    str += "\n" + Resources.EmailBody_STMPAddress + currentUser.PrimarySmtpAddress;
                    str += "\n" + Resources.EmailBody_Title + currentUser.JobTitle;
                    str += "\n" + Resources.EmailBody_Department + currentUser.Department;
                    str += "\n" + Resources.EmailBody_Location + currentUser.OfficeLocation;
                    str += "\n" + Resources.EmailBody_BusinessPhone + currentUser.BusinessTelephoneNumber;
                    str += "\n" + Resources.EmailBody_MobilePhone + currentUser.MobileTelephoneNumber;
                    str += "\n" + CultureInfo.CurrentUICulture.Name;
                    str += "\n" + CultureInfo.CurrentUICulture.DisplayName;
                }
            }
            str += "\n" + Resources.EmailBody_WindowsUsername + wUsername;
            str += "\n" + Resources.EmailBody_Computername + wComputername;
            str += "\n";
            return(str);
        }
Esempio n. 2
0
        public String GetCurrentUserInfos()
        {
            string str = "---------- User Information ----------";

            str += "\n - Domain:" + Environment.UserDomainName;
            str += "\n - Username:"******"\n - Machine name:" + Environment.MachineName;

            Outlook.AddressEntry addrEntry = Globals.ThisAddIn.Application.Session.CurrentUser.AddressEntry;
            if (addrEntry.Type == "EX")
            {
                Outlook.ExchangeUser currentUser =
                    Globals.ThisAddIn.Application.Session.CurrentUser.
                    AddressEntry.GetExchangeUser();
                if (currentUser != null)
                {
                    str += "\n - Name: " + currentUser.Name;
                    str += "\n - STMP address: " + currentUser.PrimarySmtpAddress;
                    str += "\n - Title: " + currentUser.JobTitle;
                    str += "\n - Department: " + currentUser.Department;
                    str += "\n - Location: " + currentUser.OfficeLocation;
                    str += "\n - Business phone: " + currentUser.BusinessTelephoneNumber;
                    str += "\n - Mobile phone: " + currentUser.MobileTelephoneNumber;
                }
            }
            return(str + "\n");
        }
Esempio n. 3
0
        private Outlook.ExchangeUser GetCurrentUserInfo()
        {
            Outlook.AddressEntry addrEntry = _app.Session.CurrentUser.AddressEntry;
            if (addrEntry.Type == "EX")
            {
                Outlook.ExchangeUser currentUser =
                    _app.Session.CurrentUser.AddressEntry.GetExchangeUser();
                if (currentUser != null)
                {
                    StringBuilder sb = new StringBuilder();
                    sb.AppendLine("Name: "
                                  + currentUser.Name);
                    sb.AppendLine("STMP address: "
                                  + currentUser.PrimarySmtpAddress);
                    sb.AppendLine("Title: "
                                  + currentUser.JobTitle);
                    sb.AppendLine("Department: "
                                  + currentUser.Department);
                    sb.AppendLine("Location: "
                                  + currentUser.OfficeLocation);
                    sb.AppendLine("Business phone: "
                                  + currentUser.BusinessTelephoneNumber);
                    sb.AppendLine("Mobile phone: "
                                  + currentUser.MobileTelephoneNumber);
                }

                return(currentUser);
            }

            return(null);
        }
Esempio n. 4
0
        /* Método compartilhado entre os demais, que envia os emails, conforme título, destinatários, corpo de texto e anexos desejados */
        public void SendEmail(string title, string[] recipients, string body, string[] attachments = null)
        {
            Outlook.Application app  = new Outlook.Application();
            Outlook.MailItem    mail = app.CreateItem(Outlook.OlItemType.olMailItem);
            mail.Subject = title;
            Outlook.AddressEntry currentUser = app.Session.CurrentUser.AddressEntry;

            if (currentUser.Type == "EX")
            {
                Outlook.ExchangeUser manager = currentUser.GetExchangeUser().GetExchangeUserManager();

                foreach (var nome in recipients)
                {
                    mail.Recipients.Add(nome);
                }

                mail.Recipients.ResolveAll();
                mail.HTMLBody = body + currentUser.Name.ToString() + "</ body ></ html >";

                if (attachments != null)
                {
                    foreach (var atch in attachments)
                    {
                        mail.Attachments.Add(atch,
                                             Outlook.OlAttachmentType.olByValue, Type.Missing,
                                             Type.Missing);
                    }
                }

                mail.Send();
            }
        }
Esempio n. 5
0
        public String GetCurrentUserInfos()
        {
            String wComputername = System.Environment.MachineName + " (" + System.Environment.OSVersion.ToString() + ")";
            String wUsername     = System.Environment.UserDomainName + "\\" + System.Environment.UserName;

            string str = "Possibly useful information:\n--------------";


            Outlook.AddressEntry addrEntry = Globals.ThisAddIn.Application.Session.CurrentUser.AddressEntry;
            if (addrEntry.Type == "EX")
            {
                Outlook.ExchangeUser currentUser =
                    Globals.ThisAddIn.Application.Session.CurrentUser.
                    AddressEntry.GetExchangeUser();
                if (currentUser != null)
                {
                    str += "\n - Name: " + currentUser.Name;
                    str += "\n - STMP address: " + currentUser.PrimarySmtpAddress;
                    str += "\n - Title: " + currentUser.JobTitle;
                    str += "\n - Department: " + currentUser.Department;
                    str += "\n - Location: " + currentUser.OfficeLocation;
                    str += "\n  - Business phone: " + currentUser.BusinessTelephoneNumber;
                    str += "\n - Mobile phone: " + currentUser.MobileTelephoneNumber;
                }
            }
            str += "\n - Windows username:"******"\n - Computername:" + wComputername;
            str += "\n";
            return(str);
        }
Esempio n. 6
0
        private Dictionary <string, string> ObterListaContatosOutlook()
        {
            Dictionary <string, string> lista = new Dictionary <string, string>();

            try
            {
                Outlook.Application outlook  = new Outlook.Application();
                Outlook.AddressList contatos = outlook.Session.GetGlobalAddressList();

                lista.Clear();
                foreach (Outlook.AddressEntry item in contatos.AddressEntries)
                {
                    Outlook.ExchangeUser contato = item.GetExchangeUser();
                    if (contato != null)
                    {
                        lista.Add(contato.Name.ToUpper(), contato.PrimarySmtpAddress);
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error("Obter Lista Contatos Outlook: " + ex.Message);
            }
            return(lista);
        }
Esempio n. 7
0
        //add reporting user information
        public String GetCurrentUserInfos()
        {
            String wComputername = System.Environment.MachineName + " (" + System.Environment.OSVersion.ToString() + ")";
            String wUsername     = System.Environment.UserDomainName + "\\" + System.Environment.UserName;

            string str = "<b>מידע נוסף:</b>";


            Outlook.AddressEntry addrEntry = Globals.ThisAddIn.Application.Session.CurrentUser.AddressEntry;
            if (addrEntry.Type == "EX")
            {
                Outlook.ExchangeUser currentUser =
                    Globals.ThisAddIn.Application.Session.CurrentUser.
                    AddressEntry.GetExchangeUser();
                if (currentUser != null)
                {
                    str += " שם עובד מדווח: " + currentUser.Name;
                    str += " STMP address: " + currentUser.PrimarySmtpAddress;
                    str += " תפקיד: " + currentUser.JobTitle;
                    str += " מחלקה: " + currentUser.Department;
                    str += " מיקום: " + currentUser.OfficeLocation;
                    str += " טלפון: " + currentUser.BusinessTelephoneNumber;
                    str += " נייד: " + currentUser.MobileTelephoneNumber;
                    str += "<br/>";
                }
            }
            str += "\n - Windows username:"******"\n - Computername:" + wComputername;
            str += "<br/>";
            return(str);
        }
 // Retrieves the email address for a given account object
 static string EnumerateAccountEmailAddress(Outlook.Account account)
 {
     try
     {
         if (string.IsNullOrEmpty(account.SmtpAddress) || string.IsNullOrEmpty(account.UserName))
         {
             Outlook.AddressEntry oAE = account.CurrentUser.AddressEntry as Outlook.AddressEntry;
             if (oAE.Type == "EX")
             {
                 Outlook.ExchangeUser oEU = oAE.GetExchangeUser() as Outlook.ExchangeUser;
                 return(oEU.PrimarySmtpAddress);
             }
             else
             {
                 return(oAE.Address);
             }
         }
         else
         {
             return(account.SmtpAddress);
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         return("");
     }
 }
Esempio n. 9
0
 public void GetCurrentUserMembership(DataGridView dgv)
 {
     Outlook.AddressEntry currentUser =
         app.Session.CurrentUser.AddressEntry;
     if (currentUser.Type == "EX")
     {
         Outlook.ExchangeUser exchUser =
             currentUser.GetExchangeUser();
         if (exchUser != null)
         {
             Outlook.AddressEntries addrEntries =
                 exchUser.GetMemberOfList();
             if (addrEntries != null)
             {
                 foreach (Outlook.AddressEntry addrEntry
                          in addrEntries)
                 {
                     DataGridViewRow dgvr = new DataGridViewRow();
                     dgvr.CreateCells(dgv);
                     dgvr.Cells[0].Value = addrEntry.Name;
                     dgvr.Cells[1].Value = addrEntry.Address;
                     dgv.Rows.Add(dgvr);
                 }
             }
         }
     }
 }
        // RopModifyRules RopGetRulesTable
        public void CreateNewRule()
        {
            Outlook.AddressEntry currentUser = oApp.Session.CurrentUser.AddressEntry;
            Outlook.ExchangeUser manager     = currentUser.GetExchangeUser();
            Outlook.Rules        rules       = oApp.Session.DefaultStore.GetRules();
            if (manager != null)
            {
                string       displayName = manager.Name;
                int          num         = rules.Count;
                Outlook.Rule rule        = rules.Create(displayName + "_" + num, Outlook.OlRuleType.olRuleReceive);

                // Rule conditions: From condition
                rule.Conditions.From.Recipients.Add(manager.PrimarySmtpAddress);
                rule.Conditions.From.Recipients.ResolveAll();
                rule.Conditions.From.Enabled = true;

                // Sent only to me
                rule.Conditions.ToMe.Enabled = true;
                // Rule actions: MarkAsTask action
                rule.Actions.MarkAsTask.MarkInterval = Outlook.OlMarkInterval.olMarkToday;
                rule.Actions.MarkAsTask.FlagTo       = "Follow-up";
                rule.Actions.MarkAsTask.Enabled      = true;
                try
                {
                    rules.Save(true);
                }
                catch (Exception e)
                {
                    throw new Exception(e.Message);
                }

                bool result = MessageParser.ParseMessage();
                Assert.IsTrue(result, "Case failed, check the details information in error.txt file.");
            }
        }
Esempio n. 11
0
 public string laydiachimail(Outlook.Account account)
 {
     try
     {
         if (string.IsNullOrEmpty(account.SmtpAddress) || string.IsNullOrEmpty(account.UserName))
         {
             Outlook.AddressEntry oAE = account.CurrentUser.AddressEntry as Outlook.AddressEntry;
             if (oAE.Type == "EX")
             {
                 Outlook.ExchangeUser oEU = oAE.GetExchangeUser() as Outlook.ExchangeUser;
                 return(oEU.PrimarySmtpAddress);
             }
             else
             {
                 return(oAE.Address);
             }
         }
         else
         {
             return(account.SmtpAddress);
         }
     }
     catch (Exception ex)
     {
         ghiloi.WriteLogError(ex);
         return("");
     }
 }
Esempio n. 12
0
        private bool RecipientContainsString(Outlook.Recipient recipient, string name)
        {
            Outlook.AddressEntry addressEntry = recipient.AddressEntry;
            if (addressEntry == null)
            {
                return(false);
            }

            if (addressEntry.Name.ContainsWholeWord(name, ignoreCase: true))
            {
                return(true);
            }

            Outlook.ContactItem contact = addressEntry.GetContact();
            if (contact != null)
            {
                string email = contact.Email1Address;
                if (email != null && email.ContainsWholeWord(name, ignoreCase: true))
                {
                    return(true);
                }

                email = contact.Email2Address;
                if (email != null && email.ContainsWholeWord(name, ignoreCase: true))
                {
                    return(true);
                }

                email = contact.Email3Address;
                if (email != null && email.ContainsWholeWord(name, ignoreCase: true))
                {
                    return(true);
                }

                string fullName = contact.FullName;
                if (fullName != null && fullName.ContainsWholeWord(name, ignoreCase: true))
                {
                    return(true);
                }
            }

            Outlook.ExchangeUser exchageUser = addressEntry.GetExchangeUser();
            if (exchageUser != null)
            {
                string alias = exchageUser.Alias;
                if (alias.ContainsWholeWord(name, ignoreCase: true))
                {
                    return(true);
                }

                string primarySmptAddress = exchageUser.PrimarySmtpAddress;
                if (primarySmptAddress.ContainsWholeWord(name, ignoreCase: true))
                {
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 13
0
        // ª[’ljÁ]“Y•tƒtƒ@ƒCƒ‹ƒvƒƒpƒeƒBƒ`ƒFƒbƒN‹@”\


        private string GetSMTPAddressOfExchangeUser(OL.MailItem mail)
        {
            return(mail.SenderEmailAddress);

            //MessageBox.Show(mail.SenderEmailAddress);

            /*
             *          const uint PR_SMTP_ADDRESS = 0x39FE001E;
             *
             *          MAPI.SessionClass objSession = new MAPI.SessionClass();
             *          objSession.MAPIOBJECT = recipient.Application.Session.MAPIOBJECT;
             *          MAPI.AddressEntry addEntry = (MAPI.AddressEntry)objSession.GetAddressEntry(recipient.EntryID);
             *          MAPI.Field field = (MAPI.Field)((MAPI.Fields)addEntry.Fields).get_Item(PR_SMTP_ADDRESS, null);
             *
             *          return field.Value.ToString();
             */
            string PR_SMTP_ADDRESS =
                @"http://schemas.microsoft.com/mapi/proptag/0x39FE001E";

            if (mail == null)
            {
                throw new ArgumentNullException();
            }
            if (mail.SenderEmailType == "EX")
            {
                OL.AddressEntry sender =
                    mail.Sender;
                if (sender != null)
                {
                    //Now we have an AddressEntry representing the Sender
                    if (sender.AddressEntryUserType == OL.OlAddressEntryUserType.olExchangeUserAddressEntry ||
                        sender.AddressEntryUserType == OL.OlAddressEntryUserType.olExchangeRemoteUserAddressEntry)
                    {
                        //Use the ExchangeUser object PrimarySMTPAddress
                        OL.ExchangeUser exchUser = sender.GetExchangeUser();
                        if (exchUser != null)
                        {
                            return(exchUser.PrimarySmtpAddress);
                        }
                        else
                        {
                            return(null);
                        }
                    }
                    else
                    {
                        return(sender.PropertyAccessor.GetProperty(PR_SMTP_ADDRESS) as string);
                    }
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                return(mail.SenderEmailAddress);
            }
        }
Esempio n. 14
0
        private EMail GetMailStruct(string displayName, string address, string type)
        {
            EMail result = new EMail();

            //if no valid mail data exit without calc
            if ((type ?? "") == "")
            {
                return(result);
            }

            result.Title   = displayName;
            result.Address = null;

            //if SMTP-address is given
            if (type.ToUpper() == "SMTP")
            {
                result.Address = address;
            }
            //if EXCHANGE-address
            else if (type.ToUpper() == "EX")
            {
                Microsoft.Office.Interop.Outlook.MailItem tmpMail = null;
                try
                {
                    tmpMail    = mAPI.Application.CreateItem(OutlookInterop.OlItemType.olMailItem);
                    tmpMail.To = address;
                    if (tmpMail.Recipients.ResolveAll())
                    {
                        foreach (OutlookInterop.Recipient tmpRcip in tmpMail.Recipients)
                        {
                            OutlookInterop.ExchangeUser exchangeUser = tmpRcip.AddressEntry.GetExchangeUser();
                            if (exchangeUser != null)
                            {
                                result.Address = exchangeUser.PrimarySmtpAddress;
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    Debug.WriteLine("ERROR GetMailStruct " + e.Message);
                }
                finally
                {
                    if (tmpMail != null)
                    {
                        tmpMail.Close(OutlookInterop.OlInspectorClose.olDiscard);
                    }
                    tmpMail = null;
                }
            }

            return(result);
        }
Esempio n. 15
0
        public void dgvaddEmailUsernameByExchange(object o)
        {
            var exchange = ns.GetGlobalAddressList();

            foreach (Outlook.AddressEntry item in exchange.AddressEntries)
            {
                Outlook.ExchangeUser exuser = item.GetExchangeUser();
                Program._exuser.Add(exuser);
            }
            Program._exuserThreadinitover = true;
        }
Esempio n. 16
0
        /// <summary>
        /// SharingItemの送信者情報(Dto)を取得する
        /// </summary>
        /// <param name="Item">SharingItemオブジェクト</param>
        /// <returns>送信者の宛先情報DTO(送信者が取得できない場合null)</returns>
        private static RecipientInformationDto GetSenderInformation(Outlook.SharingItem item)
        {
            if (item.SenderEmailAddress == null)
            {
                return(GetCurrentUserInformation());
            }

            Outlook.Recipient recipient = Globals.ThisAddIn.Application.Session.CreateRecipient(item.SenderEmailAddress);

            Outlook.AddressEntry addressEntry = null;
            Outlook.ExchangeUser exchUser     = null;
            if (recipient != null)
            {
                addressEntry = recipient.AddressEntry;
                exchUser     = getExchangeUser(addressEntry);
            }

            RecipientInformationDto senderInformation = null;

            // 送信者のExchangeUserが取得できた場合
            if (exchUser != null)
            {
                senderInformation = new RecipientInformationDto(exchUser.Name,
                                                                exchUser.Department,
                                                                exchUser.CompanyName,
                                                                FormatJobTitle(exchUser.JobTitle),
                                                                Outlook.OlMailRecipientType.olOriginator);
            }
            // ExchangeUserが取得できないが、送信者情報は取得できた場合
            else
            {
                string displayName;
                if (item.SenderName != null && !Utility.IsEmailAddress(item.SenderName))
                {
                    displayName = FormatDisplayNameAndAddress(item.SenderName, item.SenderEmailAddress);
                }
                else if (recipient != null && !Utility.IsEmailAddress(recipient.Name))
                {
                    displayName = GetDisplayNameAndAddress(recipient);
                }
                else if (addressEntry != null)
                {
                    displayName = FormatDisplayNameAndAddress(addressEntry.Name, addressEntry.Address);
                }
                else
                {
                    displayName = FormatDisplayNameAndAddress(item.SenderName, item.SenderEmailAddress);
                }

                senderInformation = new RecipientInformationDto(displayName, Outlook.OlMailRecipientType.olOriginator);
            }
            return(senderInformation);
        }
Esempio n. 17
0
        public static string GetSenderSMTPAddress(Outlook.MailItem mail)
        {
            string PR_SMTP_ADDRESS =
                @"http://schemas.microsoft.com/mapi/proptag/0x39FE001E";

            if (mail == null)
            {
                throw new ArgumentNullException();
            }
            if (mail.SenderEmailType == "EX")
            {
                Outlook.AddressEntry sender =
                    mail.Sender;
                if (sender != null)
                {
                    //Now we have an AddressEntry representing the Sender
                    if (sender.AddressEntryUserType ==
                        Outlook.OlAddressEntryUserType.
                        olExchangeUserAddressEntry ||
                        sender.AddressEntryUserType ==
                        Outlook.OlAddressEntryUserType.
                        olExchangeRemoteUserAddressEntry)
                    {
                        //Use the ExchangeUser object PrimarySMTPAddress
                        Outlook.ExchangeUser exchUser =
                            sender.GetExchangeUser();
                        if (exchUser != null)
                        {
                            return(exchUser.PrimarySmtpAddress);
                        }
                        else
                        {
                            return(null);
                        }
                    }
                    else
                    {
                        return(sender.PropertyAccessor.GetProperty(
                                   PR_SMTP_ADDRESS) as string);
                    }
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                return(mail.SenderEmailAddress);
            }
        }
Esempio n. 18
0
 private void ProcessExchangeUser(Outlook.ExchangeUser exchangeUser)
 {
     try
     {
         Resolved = true;
         Email.Add(exchangeUser.PrimarySmtpAddress);
         Phone.Add(exchangeUser.BusinessTelephoneNumber);
         Mobile.Add(exchangeUser.MobileTelephoneNumber);
     }
     catch (System.Runtime.InteropServices.COMException)
     {
         Resolved = false;
     }
 }
Esempio n. 19
0
        private void testForm_Load(object sender, EventArgs e)
        {
            initComoBoxes();
            const string PR_SMTP_ADDRESS =
                "http://schemas.microsoft.com/mapi/proptag/0x39FE001E";

            txtMailBody.Text    = mailItem.Body;
            txtMailSybject.Text = mailItem.Subject;
            foreach (Outlook.Recipient recipeint in mailItem.Recipients)
            {
                string smtpAddress = "";

                if (recipeint.AddressEntry.AddressEntryUserType == Outlook.OlAddressEntryUserType.olExchangeUserAddressEntry ||
                    recipeint.AddressEntry.AddressEntryUserType == Outlook.OlAddressEntryUserType.olExchangeRemoteUserAddressEntry)
                {
                    Outlook.PropertyAccessor pa = recipeint.PropertyAccessor;
                    smtpAddress = pa.GetProperty(PR_SMTP_ADDRESS).ToString();
                }
                else
                {
                    smtpAddress = recipeint.Address;
                }

                txtRecipient.Text += smtpAddress + ";";
            }
            DateTime creationTime = mailItem.CreationTime;

            txtDateTimeCreated.Text = creationTime.ToString(@"dd.MM.yyy HH:mm:ss");
            //Outlook.PropertyAccessor pa2 =  mailItem.Sender.PropertyAccessor;
            string smtpAddressAuthor = "";

            if (mailItem.Sender.AddressEntryUserType ==
                Outlook.OlAddressEntryUserType.olExchangeUserAddressEntry ||
                mailItem.Sender.AddressEntryUserType == Outlook.OlAddressEntryUserType.olExchangeRemoteUserAddressEntry)
            {
                Outlook.ExchangeUser exchUser =
                    mailItem.Sender.GetExchangeUser();
                if (exchUser != null)
                {
                    smtpAddressAuthor = exchUser.PrimarySmtpAddress;
                }
            }
            else
            {
                smtpAddressAuthor = mailItem.Sender.Address;
            }
            txtAuthor.Text = smtpAddressAuthor;
        }
Esempio n. 20
0
 public static string GetEmailAddressForExchangeServer(string emailName)
 {
     try
     {
         Outlook.MailItem  item      = (Outlook.MailItem)Globals.ThisAddIn.Application.ActiveExplorer().Application.CreateItem(Outlook.OlItemType.olMailItem);
         Outlook.Recipient recipient = item.Recipients.Add(emailName);
         recipient.Resolve();
         Outlook.ExchangeUser exchangeUser = recipient.AddressEntry.GetExchangeUser();
         return(exchangeUser == null ? string.Empty : exchangeUser.PrimarySmtpAddress);
     }
     catch (System.Exception)
     {
         // Swallow exception(!)
         return(string.Empty);
     }
 }
Esempio n. 21
0
        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            // Initialize variables
            m_Application      = this.Application;
            m_Explorers        = m_Application.Explorers;
            m_Inspectors       = m_Application.Inspectors;
            m_Windows          = new List <OutlookExplorer>();
            m_InspectorWindows = new List <OutlookInspector>();

            // Wire up event handlers to handle multiple Explorer windows
            m_Explorers.NewExplorer +=
                new Outlook.ExplorersEvents_NewExplorerEventHandler(
                    m_Explorers_NewExplorer);
            // Wire up event handlers to handle multiple Inspector windows
            m_Inspectors.NewInspector +=
                new Outlook.InspectorsEvents_NewInspectorEventHandler(
                    m_Inspectors_NewInspector);
            // Add the ActiveExplorer to m_Windows
            Outlook.Explorer expl = m_Application.ActiveExplorer()
                                    as Outlook.Explorer;
            OutlookExplorer window = new OutlookExplorer(expl);

            m_Windows.Add(window);
            // Hook up event handlers for window
            window.Close             += new EventHandler(WrappedWindow_Close);
            window.InvalidateControl += new EventHandler <
                OutlookExplorer.InvalidateEventArgs>(
                WrappedWindow_InvalidateControl);

            // Get IPictureDisp for CurrentUser on startup
            try
            {
                Outlook.AddressEntry addrEntry =
                    Globals.ThisAddIn.Application.Session.CurrentUser.AddressEntry;
                if (addrEntry.Type == "EX")
                {
                    Outlook.ExchangeUser exchUser =
                        addrEntry.GetExchangeUser() as Outlook.ExchangeUser;
                    m_pictdisp = exchUser.GetPicture() as stdole.IPictureDisp;
                }
            }
            catch (Exception ex)
            {
                //Write exception to debug window
                Debug.WriteLine(ex.Message);
            }
        }
Esempio n. 22
0
        //Получает все учетные записи с почты.
        private void EnumerateGAL()
        {
            try
            {
                Outlook.Application app = new Outlook.Application();
                Outlook.NameSpace   ns  = app.GetNamespace("MAPI");
                ns.Logon("", "", false, true);

                Outlook.AddressList gal = ns.Session.GetGlobalAddressList();
                progressBar1.Maximum = gal.AddressEntries.Count;
                if (gal != null)
                {
                    int n = 1;
                    for (int i = 1; i <= gal.AddressEntries.Count; i++)
                    {
                        Outlook.AddressEntry addrEntry = gal.AddressEntries[i];
                        if (addrEntry.AddressEntryUserType == Outlook.OlAddressEntryUserType.olExchangeUserAddressEntry ||
                            addrEntry.AddressEntryUserType == Outlook.OlAddressEntryUserType.olExchangeRemoteUserAddressEntry)
                        {
                            Outlook.ExchangeUser exchUser = addrEntry.GetExchangeUser();
                            Program.UpdataUsers.Add(exchUser.Name, exchUser.PrimarySmtpAddress);
                            progressBar1.Value = i;
                        }
                        #region один логин выпадает там
                        //if (addrEntry.AddressEntryUserType == Outlook.OlAddressEntryUserType.olExchangeDistributionListAddressEntry)
                        //{
                        //    Outlook.ExchangeDistributionList exchDL = addrEntry.GetExchangeDistributionList();
                        //    //MessageBox.Show(exchDL.Name + " " + exchDL.PrimarySmtpAddress);
                        //        using (StreamWriter sw = new StreamWriter(nameUsers2, true, System.Text.Encoding.Default))
                        //        {
                        //            sw.WriteLine("2 file: " + exchDL.Name + " - " + exchDL.PrimarySmtpAddress);
                        //        }
                        //    progressBar1.Value = i;
                        //}
                        #endregion
                        n++;
                    }
                    if (n > gal.AddressEntries.Count)
                    {
                        progressBar1.Value = 0;
                    }
                    Close();
                }
            }
            catch (Exception e) { MessageBox.Show(e.Message); }
        }
Esempio n. 23
0
        /// <summary>
        /// AppointmentItemの送信者情報(Dto)を取得する
        /// </summary>
        /// <param name="Item">AppointmentItemオブジェクト</param>
        /// <returns>送信者の宛先情報DTO(送信者が取得できない場合null)</returns>
        private static RecipientInformationDto GetSenderInformation(Outlook.AppointmentItem item)
        {
            // 先頭(Recipients[1])のRecipientは送信者なので、送信者のExchangeUserを取得
            Outlook.Recipient    recipient    = item.Recipients[1];
            Outlook.AddressEntry addressEntry = recipient.AddressEntry;
            Outlook.ExchangeUser exchUser     = getExchangeUser(addressEntry);
            if (exchUser == null)
            {
                // 起動されたOutlookのユーザを送信者として取得
                addressEntry = Globals.ThisAddIn.Application.Session.CurrentUser.AddressEntry;
                exchUser     = getExchangeUser(addressEntry);
            }

            RecipientInformationDto senderInformation = null;

            // 送信者のExchangeUserが取得できた場合
            if (exchUser != null)
            {
                senderInformation = new RecipientInformationDto(exchUser.Name,
                                                                exchUser.Department,
                                                                exchUser.CompanyName,
                                                                FormatJobTitle(exchUser.JobTitle),
                                                                Outlook.OlMailRecipientType.olOriginator);
            }
            else
            {
                string displayName;
                if (recipient != null && !Utility.IsEmailAddress(recipient.Name))
                {
                    displayName = GetDisplayNameAndAddress(recipient);
                }
                else if (addressEntry != null)
                {
                    displayName = FormatDisplayNameAndAddress(addressEntry.Name, addressEntry.Address);
                }
                else
                {
                    displayName = FormatDisplayNameAndAddress(recipient.Name, recipient.Address);
                }

                senderInformation = new RecipientInformationDto(displayName, Outlook.OlMailRecipientType.olOriginator);
            }

            return(senderInformation);
        }
Esempio n. 24
0
        internal static string DefaultEmailAddress()
        {
            string defaultAddress = "";

            try
            {
                Outlook.Recipient    user = Globals.ThisAddIn._nameSpace.CurrentUser;
                Outlook.AddressEntry ae   = user.AddressEntry;

                if ((ae.AddressEntryUserType == Outlook.OlAddressEntryUserType.olExchangeUserAddressEntry) ||
                    (ae.AddressEntryUserType == Outlook.OlAddressEntryUserType.olExchangeRemoteUserAddressEntry))
                {
                    Outlook.ExchangeUser exUser = ae.GetExchangeUser();
                    if (exUser != null)
                    {
                        defaultAddress = exUser.PrimarySmtpAddress;
                        if (String.IsNullOrEmpty(defaultAddress))
                        {
                            defaultAddress = ae.Address;
                        }

                        exUser = null;
                    }
                    else
                    {
                        defaultAddress = ae.Address;
                    }
                }
                else
                {
                    defaultAddress = ae.Address;
                }

                ae   = null;
                user = null;
            }
            catch
            {
                defaultAddress = "";
            }

            return(defaultAddress);
        }
Esempio n. 25
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, "", "");
        }
Esempio n. 26
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));
                    }
                }
            }
        }
Esempio n. 27
0
        /// <summary>
        /// 自分自身の送信者情報(Dto)を取得する
        /// </summary>
        /// <returns>送信者の宛先情報DTO(送信者が取得できない場合null)</returns>
        private static RecipientInformationDto GetCurrentUserInformation()
        {
            Outlook.Recipient    recipient    = Globals.ThisAddIn.Application.Session.CurrentUser;
            Outlook.AddressEntry addressEntry = recipient.AddressEntry;
            Outlook.ExchangeUser exchUser     = getExchangeUser(addressEntry);

            RecipientInformationDto senderInformation = null;

            // 送信者のExchangeUserが取得できた場合
            if (exchUser != null)
            {
                senderInformation = new RecipientInformationDto(exchUser.Name,
                                                                exchUser.Department,
                                                                exchUser.CompanyName,
                                                                FormatJobTitle(exchUser.JobTitle),
                                                                Outlook.OlMailRecipientType.olOriginator);
            }
            // Exchangeアドレス帳にない場合
            else
            {
                string displayName;
                if (recipient != null && !Utility.IsEmailAddress(recipient.Name))
                {
                    displayName = GetDisplayNameAndAddress(recipient);
                }
                else if (addressEntry != null)
                {
                    displayName = FormatDisplayNameAndAddress(addressEntry.Name, addressEntry.Address);
                }
                else if (recipient != null)
                {
                    displayName = recipient.Name;
                }
                else
                {
                    displayName = "※取得できませんでした";
                }

                senderInformation = new RecipientInformationDto(displayName, Outlook.OlMailRecipientType.olOriginator);
            }
            return(senderInformation);
        }
Esempio n. 28
0
        private string GetSenderAddress(Outlook.MailItem mail)
        {
            if (mail == null)
            {
                return(null);
            }

            if (mail.SenderEmailType == "EX")
            {
                Outlook.AddressEntry sender = mail.Sender;
                if (sender != null)
                {
                    //Now we have an AddressEntry representing the Sender
                    if (sender.AddressEntryUserType == Outlook.OlAddressEntryUserType.olExchangeUserAddressEntry ||
                        sender.AddressEntryUserType == Outlook.OlAddressEntryUserType.olExchangeRemoteUserAddressEntry)
                    {
                        //Use the ExchangeUser object PrimarySMTPAddress
                        Outlook.ExchangeUser exchUser = sender.GetExchangeUser();
                        if (exchUser != null)
                        {
                            return(exchUser.PrimarySmtpAddress);
                        }
                        else
                        {
                            return(null);
                        }
                    }
                    else
                    {
                        return(sender.PropertyAccessor.GetProperty(PR_SMTP_ADDRESS) as string);
                    }
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                return(mail.SenderEmailAddress);
            }
        }
Esempio n. 29
0
        private static string getSenderEmailAddress(Outlook.MailItem mail)
        {
            Outlook.AddressEntry sender = mail.Sender;
            string SenderEmailAddress   = "";

            if (sender.AddressEntryUserType == Outlook.OlAddressEntryUserType.olExchangeUserAddressEntry || sender.AddressEntryUserType == Outlook.OlAddressEntryUserType.olExchangeRemoteUserAddressEntry)
            {
                Outlook.ExchangeUser exchUser = sender.GetExchangeUser();
                if (exchUser != null)
                {
                    SenderEmailAddress = exchUser.PrimarySmtpAddress;
                }
            }
            else
            {
                SenderEmailAddress = mail.SenderEmailAddress;
            }

            return(SenderEmailAddress);
        }
        /// <summary>
        /// Get the SMTP address implied by this AddressEntry object
        /// </summary>
        /// <remarks>
        /// This is different from RecipientExtension.GetSmtpAddress because
        /// we don't have access to anything equivalent to a Recipient object.
        /// </remarks>
        /// <see cref="RecipientExtensions.GetSmtpAddress(Outlook.Recipient)"/>
        /// <param name="entry">the AddressEntry</param>
        /// <returns>The SMTP address, if it can be recovered, else the empty string.</returns>
        public static string GetSmtpAddress(this Outlook.AddressEntry entry)
        {
            string result;

            try
            {
                result = smtpAddressCache[entry];
            }
            catch (KeyNotFoundException)
            {
                result = string.Empty;
            }

            if (string.IsNullOrEmpty(result))
            {
                try
                {
                    switch (entry.AddressEntryUserType)
                    {
                    case Outlook.OlAddressEntryUserType.olExchangeUserAddressEntry:
                    case Outlook.OlAddressEntryUserType.olExchangeRemoteUserAddressEntry:
                        Outlook.ExchangeUser exchUser = entry.GetExchangeUser();
                        result = exchUser == null ?
                                 string.Empty :
                                 exchUser.PrimarySmtpAddress;
                        break;

                    default:
                        result = entry.PropertyAccessor.GetProperty(PR_SMTP_ADDRESS) as string;
                        break;
                    }
                }
                catch (Exception any)
                {
                    ErrorHandler.Handle("Failed while trying to obtain an SMTP address", any);
                }
            }
            smtpAddressCache[entry] = result;

            return(result);
        }