Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/272.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Outlook:如何从收件人字段获取电子邮件?_C#_Visual Studio_Outlook_Vsto - Fatal编程技术网

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

C# Outlook:如何从收件人字段获取电子邮件?,c#,visual-studio,outlook,vsto,C#,Visual Studio,Outlook,Vsto,我正在尝试在“撰写邮件”窗口的“收件人”字段中键入电子邮件地址 我尝试获取收件人的Address属性,根据VS,该属性应该给我电子邮件 我收到的字符串如下所示: "/c=US/a=att/p=Microsoft/o=Finance/ou=Purchasing/s=Furthur/g=Joe" 如何获取收件人字段中的电子邮件地址 到目前为止,我的代码是: List <string> emails = new List<string>(); if (thisMailIte

我正在尝试在“撰写邮件”窗口的“收件人”字段中键入电子邮件地址

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

我收到的字符串如下所示:

"/c=US/a=att/p=Microsoft/o=Finance/ou=Purchasing/s=Furthur/g=Joe"
如何获取收件人字段中的电子邮件地址

到目前为止,我的代码是:

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

if (thisMailItem.Recipients.Count > 0)
{
    foreach (Recipient rec in thisMailItem.Recipients)
    {
        emails.Add(rec.Address);
    }
}
return emails;
列出电子邮件=新建列表();
如果(thisMailItem.Recipients.Count>0)
{
foreach(thisMailItem.Recipients中的收件人记录)
{
电子邮件。添加(记录地址);
}
}
回复邮件;
你能试试这个吗

emails.Add(rec.AddressEntry.Address);

编辑:

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

string email1Address = rec.AddressEntry.GetContact().Email1Address;
.email2Address
.Email3Address

还有,

rec.AddressEntry.GetExchangeUser().Address

你可能想试试

AddressEntry还有一个
SMTPAddress
属性,用于公开用户的主smtp地址。

我不知道这是否有帮助,也不知道准确程度如何

it is, a sample

    private string GetSmtp(Outlook.MailItem item)
        {
            try
            {
                if (item == null || item.Recipients == null || item.Recipients[1] == null) return "";
                var outlook = new Outlook.Application();
                var session = outlook.GetNamespace("MAPI");
                session.Logon("", "", false, false);
                var entryId = item.Recipients[1].EntryID;
                string address = session.GetAddressEntryFromID(entryId).GetExchangeUser().PrimarySmtpAddress;
                if (string.IsNullOrEmpty(address))
                {
                    var rec = item.Recipients[1];
                    var contact = rec.AddressEntry.GetExchangeUser();
                    if (contact != null)
                        address = contact.PrimarySmtpAddress;
                }
                if (string.IsNullOrEmpty(address))
                {
                    var rec = item.Recipients[1];
                    var contact = rec.AddressEntry.GetContact();
                    if (contact != null)
                        address = contact.Email1Address;
                }
                return address;
            }
            finally
            {

            }
        }
试试这个

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;

        }
这在MSDN上提供


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

我刚刚尝试过,rec.Address和rec.AddressEntry.Address返回相同的结果。meow.GetExchangeUser().PrimarySmtpAddress是答案:)当用户注册了多种“地址”类型时,address属性默认为电子邮件以外的内容,因此您必须指定哪种类型的地址。谢谢你的尝试!为了便于将来参考,在VS2010中,它是rec.AddressEntry.GetExchangeUser().PrimarySMTPAddress