开发者

How can I return the primary email address associated with the logged on user's current Outlook profile?

I know, it's a bit weird asking for a query to tell me my own email address right, I'll explain further...

I'm writing a COM add-in for Outlook 2007. One of the subs generates and sends an email to a particular address and this all works fine. However I have a need to have an option for the sender to be able to include themselves on the recipients list. As more than one person will be running this I cannot just set the sender's email address manually and would prefer to just add a check box on 开发者_如何学Pythonthe form to enable this feature.

The only bit I'm stuck on is working out how to find the email address of the person sending the email. I could do it with an AD query against the logged on user but this needs to work for non-domain users also so need another method.

To put it more succinctly: Using VB, how can I return the primary email address associated with the logged-on user's current Outlook profile?


Application.Session.CurrentUser.AddressEntry.GetExchangeUser.PrimarySmtpAddress
or
RDOSession.CurrentUser.SmtpAddress


Take a look using the property accessor to get the mapi property

If the account type is EX, PR_SMTP_ADDRESS or it DASL "http://schemas.microsoft.com/mapi/proptag/0x39FE001E"

Though reading you question again are some the accounts non Exchange ?

Marcus


If you are using Outlook Redemption then @bugtussle's solution works but you have to be logged on via Redemption first. Since Redemption documentation is horrible, here's the full code that worked for me:

RDOSession session = new RDOSession();
session.Logon(null, null, null, true, null, null);
string emailAddress = session.CurrentUser.SMTPAddress;
session.Logoff();
return emailAddress;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜