获取 Outlook 2007 中当前用户的电子邮件地址

发布于 2024-10-13 10:07:08 字数 76 浏览 7 评论 0原文

我有一个用 C# 编写的 Outlook 插件。

我想知道如何或是否可以获得当前用户的电子邮件地址?

谢谢

I have an Outlook add in written in C#.

I was wondering how or if I could get the email address of the current user?

Thanks

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

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

发布评论

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

评论(6

岁月静好 2024-10-20 10:07:08

在 VS 2010、.NET 4.0、Outlook 2010 中测试:

var emailAddress = this.Application.ActiveExplorer().Session.CurrentUser.AddressEntry.GetExchangeUser().PrimarySmtpAddress;

Tested in VS 2010, .NET 4.0, Outlook 2010:

var emailAddress = this.Application.ActiveExplorer().Session.CurrentUser.AddressEntry.GetExchangeUser().PrimarySmtpAddress;
离不开的别离 2024-10-20 10:07:08

取决于“当前用户地址”的定义。

  1. Outlook 中主帐户的地址可以从 Appication.Session.CurrentUser 检索(返回 Recipient 对象)。使用Recipient.Address 属性。但请注意,对于 Exchange 帐户 (Recipient.AddressEntry.Type == "EX"),您将收到 EX 类型地址。要检索 SMTP 地址,请使用 Recipient.AddressEntry.GetExchangeUser().PrimarySmtpAddress。准备好在出现错误时处理空值/异常。

在扩展 MAPI 级别(C++ 或 Delphi)上,使用 IMAPISession::QueryIdentity (您可以在 OutlookSpy - 我是其作者 - 单击 IMAPISession 按钮,然后单击 QueryIdentity)。然后,您可以读取 PR_ADDRTYPE 属性(“EX”与“SMTP”)和 PR_EMAIL_ADDRESS(当 PR_ADDRTYPE = “SMTP”时)或(在如果是 Exchange)PR_SMTP_ADDRESS(不保证存在)和 PR_EMS_AB_PROXY_ADDRESSES(具有 Exchange 地址的多值属性,包括所有代理(别名)地址、EX 和 SMTP)。

  1. 如果配置文件中有多个帐户,则可以通过多个帐户发送或接收电子邮件。在这种情况下,请使用 MailItem.SendUsingAccount (返回 Account 对象,可以为 null - 在这种情况下使用 Application.Session.CurrentUser)。这对于接收、发送或撰写的电子邮件均有效(Application.ActiveInspector.CurrentItemApplication.ActiveExplorer.ActiveInlineResponse)。

  2. 可以使用Namespace.Accounts集合(Application.Session.Accounts)访问给定配置文件中的所有帐户。可以使用 Account.SmtpAddress 属性访问帐户的地址。
    请注意,Outlook 对象模型仅公开邮件帐户。某些商店帐户(例如 PST)不在集合中,因为即使某些其他帐户(例如 POP3/SMTP)可以传送到该商店,它们也没有固有的用户身份。如果您想访问所有帐户,您可以使用 Redemption (我是其作者)及其 < a href="http://www.dimastr.com/redemption/rdosession.htm" rel="nofollow noreferrer">RDOSession.Accounts 集合 (RDOAccounts 对象)。

在扩展 MAPI 级别,帐户通过 IOlkAccountManager 界面。如果您单击 IOlkAccountManager 按钮,您可以在 OutlookSpy(我是其作者)中使用它。

  1. 对于委托 Exchange 存储,存储所有者不会通过 Outlook 对象模型公开。您可以使用扩展 MAPI(请注意,PR_MAILBOX_OWNER_ENTRYID 属性仅由在线商店公开,在缓存商店中不可用)。您可以解析 Exchange 存储条目 ID 并从中提取 EX 类型地址。然后,您可以根据给定的 EX 地址构造 GAL 对象条目 id。您还可以使用兑换(我是其作者)及其RDOExchangeMailboxStore 对象及其 Owner 属性。

Depends on the definition of "the current user address".

  1. The address of the primary account in Outlook can be retrieved from Appication.Session.CurrentUser (returns Recipient object). Use Recipient.Address property. Note however that for an Exchange account (Recipient.AddressEntry.Type == "EX") you will receive an EX type address. To retrieve the SMTP address, use Recipient.AddressEntry.GetExchangeUser().PrimarySmtpAddress. Be prepared to handle nulls/exceptions in case of errors.

On the Extended MAPI level (C++ or Delphi), use IMAPISession::QueryIdentity (you can test it in OutlookSpy - I am its author - click IMAPISession button, then QueryIdentity). You can then read the PR_ADDRTYPE property ("EX" vs "SMTP") and PR_EMAIL_ADDRESS (when PR_ADDRTYPE = "SMTP") or (in case of Exchange) PR_SMTP_ADDRESS (not guaranteed to be present) and PR_EMS_AB_PROXY_ADDRESSES (multivalued property with Exchange addresses, including all proxy (alias) addresses, EX and SMTP).

  1. In case of multiple accounts in the profile, an email can be sent or received through multiple accounts. In that case use MailItem.SendUsingAccount (returns Account object, can be null - in that case use Application.Session.CurentUser). This is valid both for received, sent or emails being composed (Application.ActiveInspector.CurrentItem or Application.ActiveExplorer.ActiveInlineResponse).

  2. All accounts in a given profile can be accessed using the Namespace.Accounts collection (Application.Session.Accounts). Account's address can be accessed using Account.SmtpAddress property.
    Note that the Outlook Object Model only exposes mail accounts. Some store accounts (such as PST) are not in the collection since they do not have an intrinsic user identity even if some other accounts (such as POP3/SMTP) can deliver to that store. If you want to access all accounts, you can use Redemption (I am its author) and its RDOSession.Accounts collection (RDOAccounts object).

On the Extended MAPI level, the accounts are exposed through the IOlkAccountManager interface. You can play with it in OutlookSpy (I am its author) if you click the IOlkAccountManager button.

  1. In case of delegate Exchange stores, the store owner is not exposed through the Outlook Object Model. You can either use Extended MAPI (note that the PR_MAILBOX_OWNER_ENTRYID property is only exposed by the online store, it is not available in a cached store). You can parse the Exchange store entry id and extract the EX type address from it. You can then construct the GAL object entry id given the EX address. You can also access the store owner using Redemption (I am its author) and its RDOExchangeMailboxStore object and its Owner property.
自由如风 2024-10-20 10:07:08

如果您使用普通的 POP/IMAP 服务器,您将获得以下电子邮件地址:
Application.Session.CurrentUser.AddressEntry.Address;

使用 Exchange Server,您可以通过以下方式获取电子邮件地址:
Application.Session.CurrentUser.AddressEntry.GetExchangeUser().PrimarySmtpAddress;

If you are using the normal POP/IMAP server, you get the e-mail address with:
Application.Session.CurrentUser.AddressEntry.Address;

With Exchange Server, you get the e-mail address with:
Application.Session.CurrentUser.AddressEntry.GetExchangeUser().PrimarySmtpAddress;

記柔刀 2024-10-20 10:07:08

尝试outlookObject.ActiveExplorer().Session.CurrentUser.Address。为我工作过 VS10、Outlook 2007、.NET 4.0

Try outlookObject.ActiveExplorer().Session.CurrentUser.Address. Worked for me on VS10, Outlook 2007, .NET 4.0

做个ˇ局外人 2024-10-20 10:07:08

任何路过的人,我强烈建议使用 Application.Session.CurrentUser.AddressEntry.Address
而不是使用任何东西
Application.ActiveExplorer().Session,
因为 ActiveExplorer() 可能会返回 NullReferenceException,例如通过 Outlook 打开电子邮件时。

Anyone passing by, I'd strongly advice using Application.Session.CurrentUser.AddressEntry.Address
instead of anything using
Application.ActiveExplorer().Session,
as ActiveExplorer() might return a NullReferenceException, for instance when opening an email via Outlook.

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