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

发布于 2024-10-18 03:19:41 字数 491 浏览 3 评论 0原文

我正在尝试获取在撰写邮件窗口的收件人字段中输入的电子邮件地址。

我尝试获取收件人的地址属性,根据 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;

I'm attempting to get the email address typed into the To field of a compose mail window.

I try to get the Address property of a Recipient, which according to VS, should give me the email.

I am instead receiving a string that looks like this:

"/c=US/a=att/p=Microsoft/o=Finance/ou=Purchasing/s=Furthur/g=Joe"

How can I get the email address in the recipient field?

My code so far:

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

转身以后 2024-10-25 03:19:41

你能试试这个吗?

emails.Add(rec.AddressEntry.Address);

参考链接

编辑:

我没有合适的环境来测试,所以我只是猜测所有这些,但是

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

.Email2Adress.Email3Address

又如何,

rec.AddressEntry.GetExchangeUser().Address

您可能想尝试一下。

Can you try this ?

emails.Add(rec.AddressEntry.Address);

Reference link

EDIT:

I don't have the right environment to test so I'm just guessing all this, but how about

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

or .Email2Adress or .Email3Address

Also there is,

rec.AddressEntry.GetExchangeUser().Address

that you might want to try.

嗳卜坏 2024-10-25 03:19:41

试试这个

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 此处

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

Try this

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;

        }

This is available on MSDN here

I have used the same way to get email addresses in my application and its working.

微暖i 2024-10-25 03:19:41

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

the AddressEntry also has an SMTPAddress property that exposes the primary smtp adress of the user.

冷默言语 2024-10-25 03:19:41

我不知道这是否有帮助或有多准确

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
            {

            }
        }

I don't know if this helps or how accurate

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
            {

            }
        }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文