Outlook:如何从收件人字段中获取电子邮件?

Cat*_*Cat 8 c# outlook vsto visual-studio

我正在尝试将电子邮件地址输入到撰写邮件窗口的" 收件人"字段中.

我尝试获取收件人的地址属性,根据VS,应该给我电子邮件.

我收到一个看起来像这样的字符串:

"/c=US/a=att/p=Microsoft/o=Finance/ou=Purchasing/s=Furthur/g=Joe"
Run Code Online (Sandbox Code Playgroud)

如何在收件人字段中获取电子邮件地址?

我的代码到目前为止:

List <string> emails = new List<string>();

if (thisMailItem.Recipients.Count > 0)
{
    foreach (Recipient rec in thisMailItem.Recipients)
    {
        emails.Add(rec.Address);
    }
}
return emails;
Run Code Online (Sandbox Code Playgroud)

Bal*_*a R 5

你能试试吗?

emails.Add(rec.AddressEntry.Address);
Run Code Online (Sandbox Code Playgroud)

参考链接

编辑:

我没有合适的测试环境所以我只是猜测这一切,但是怎么样

string email1Address = rec.AddressEntry.GetContact().Email1Address;
Run Code Online (Sandbox Code Playgroud)

.Email2Adress.Email3Address

还有,

rec.AddressEntry.GetExchangeUser().Address
Run Code Online (Sandbox Code Playgroud)

您可能想尝试一下.

  • GetExchangeUser().PrimarySmtpAddress是答案:)当有多个"地址"类型注册到用户时,Address属性默认为电子邮件以外的其他内容,因此您必须指定哪种类型的地址.谢谢你的尝试! (2认同)

Aka*_*aur 5

尝试这个

private string GetSMTPAddressForRecipients(Recipient recip)
        {
            const string PR_SMTP_ADDRESS =
                "http://schemas.microsoft.com/mapi/proptag/0x39FE001E";

            PropertyAccessor pa = recip.PropertyAccessor;
            string smtpAddress = pa.GetProperty(PR_SMTP_ADDRESS).ToString();
            return smtpAddress;

        }
Run Code Online (Sandbox Code Playgroud)

这可以在 MSDN 上找到

我在我的应用程序及其工作中使用了相同的方法来获取电子邮件地址。