C# OutLook 二次开发 获取当前选中的邮箱地址

2019-01-02 20:30发布

问题:

请问各位大神,如何获取Outlook界面当前选中的邮件的发件人地址呢?

我试了很多种方法都不行!

回答1:

/// <summary>
/// 获取运单号
/// </summary>
public List<string> GetMailItem()
{
List<string> Hawbs = new List<string>();
//Outlook._Application oApp = new Outlook.Application();
Microsoft.Office.Interop.Outlook.Application oApp = new Microsoft.Office.Interop.Outlook.Application();
if (oApp.ActiveExplorer().Selection.Count > 0)
{
Object selObject = oApp.ActiveExplorer().Selection[1];

            if (selObject is Microsoft.Office.Interop.Outlook.MailItem)
            {
                Microsoft.Office.Interop.Outlook.MailItem mailItem = (selObject as Microsoft.Office.Interop.Outlook.MailItem);
                //String htmlBody = mailItem.HTMLBody;
                string Body = mailItem.Body.ToString();
                // string input = "18511999 1950 19052003";
                string pattern = @"[0-9]{10}";
                // MatchCollection match = Regex.Matches(Body, pattern);
                foreach (Match item in Regex.Matches(Body, pattern))
                {
                    Hawbs.Add(item.Value);
                }
                //for (int i = 0; i < match.Count; i++)
                //{
                //    Hawbs.Add(match[i].Value);
                //}
            }
        }

        return Hawbs;
    }


标签: