Email Address of the Current User

Hi,

How can I get the Email Address of the Login User from Outlook.

The Me.Session.CurrentUser.address return a lot of additional data, what I want is just the Email Address.

Thanks.

Andy Ho

[222 byte] By [AndyHo] at [2007-12-25]
# 1
To get the SMTP address from an Exchange sender or recipient in versions before Outlook 2007, use CDO 1.21 (which isn't supported in .NET languages) or Redemption and the PR_EMAIL (&H39FE001E) MAPI property to obtain the SMTP address from the AddressEntry object. See http://www.outlookcode.com/d/code/getsenderaddy.htm#redemption and http://www.cdolive.com/cdo5.htm#EMailAddressOfSender for examples.

--

Sue Mosher, Outlook MVP
wrote in message news:ca830d83-12e4-4e01-89ae-fc579c7d80ab@discussions.microsoft.com...

> Hi,

>

> How can I get the Email Address of the Login User from Outlook.

>

> The Me.Session.CurrentUser.address return a lot of additional data, what

> I want is just the Email Address.

>

> Thanks.

>

> Andy Ho

>

>

>

>

MVPUser at 2007-9-3 > top of Msdn Tech,Visual Studio Tools for Office,Visual Studio Tools for Office...
# 2

This is returning the X400 name for your exchange server. I am not sure this is possible through the basic Outlook Object Model, you could use LDAP and query the Exchange server settings to get the SMTP based address. This newsgroup is more for VSTO Related queries.

Sample VBScript file

' Create the ADSystem Information Object

Set objADSystemInfo = CreateObject("ADSystemInfo")
' Get the current information into a new Object
Set objUser = GetObject("LDAP://" & objADSystemInfo.UserName)

'Now use the mail property for the SMTP Address
Wscript.Echo "SMTP Address: " & objUser.mail

Additionally you could use CDO but this isnt supported using Managed code :(

Regards

MikeWalker at 2007-9-3 > top of Msdn Tech,Visual Studio Tools for Office,Visual Studio Tools for Office...
# 3

Thanks for the reply.

Really surprise that for a tool to write Outlook plug-in doesn't have any method to retrieve the user's email address. 8-(

Andy

AndyHo at 2007-9-3 > top of Msdn Tech,Visual Studio Tools for Office,Visual Studio Tools for Office...
# 4
Outlook 2007 will return the SMTP address, even for Exchange users.
SueMosher-OutlookMVP at 2007-9-3 > top of Msdn Tech,Visual Studio Tools for Office,Visual Studio Tools for Office...
# 5
Yes, very surprising that it has to be so difficult. It _should be_ (but isn't) just as easy as something like this:
myEmailAddress = this.ActiveExplorer().Session.CurrentUser.EmailAddress; (Notice: EmailAddress was made up by me)

Is there really no other way, to get the current user's e-mail address, than using Redemption in .Net 2005 (using C#) since Redemption is costly.

I heard something about asking Active Directory for the e-mail address by giving it the current username (which is easy to retrieve).

If not, what about LDAP, could someone please show some example code on how to do that in C#? (that visual basic script above here really confuses me) ;)

Thanks in advance
Magnus

ripern at 2007-9-3 > top of Msdn Tech,Visual Studio Tools for Office,Visual Studio Tools for Office...
# 6

Hi Mike,

It seems that the code snippet u have put could be of my help in my scenarios.

Can you let me know, how to use ur code in the InfoPath 2003 forms to get the

current user and his Manager's name and email IDs from the Exchange Server.

I need to display them on an InfoPath 2003 form.

Thanx for any help.

zullu at 2007-9-3 > top of Msdn Tech,Visual Studio Tools for Office,Visual Studio Tools for Office...
# 7

Mike,

I have tried placing the code in the onload event, but I am getting an error on the line below:

Set objUser = GetObject("LDAP://" & objADSystemInfo.UserName)

with the message saying "A runtime error has occured. Do you want to debug - Y/N".

And the debugger stops at this line.

Not sure about this LDAP thing, as I am a newbee.

Can u explain me why are we using LDAP and not anything else.

Moreover can you reply me soon, so that I may give you more details to get this issue resolved.

Thanx again in advance.

--

Hi Mike,

It seems that the code snippet u have put could be of my help in my scenarios.

Can you let me know, how to use ur code in the InfoPath 2003 forms to get the

current user and his Manager's name and email IDs from the Exchange Server.

I need to display them on an InfoPath 2003 form.

Thanx for any help.

zullu at 2007-9-3 > top of Msdn Tech,Visual Studio Tools for Office,Visual Studio Tools for Office...
# 8
Is there a quick way to do this in .NET 2.0 (C#)?
007DeeJay at 2007-9-3 > top of Msdn Tech,Visual Studio Tools for Office,Visual Studio Tools for Office...
# 9
Do what, 007DeeJay, for what version of Outlook? This discussion has covered several related, but different issues. Please be specific on what you're trying to do.
SueMosher-OutlookMVP at 2007-9-3 > top of Msdn Tech,Visual Studio Tools for Office,Visual Studio Tools for Office...
# 10
After digging around for a while, I finally learned that I needed to search for a way to get a user's email address from active directory using only the user's login. The method I eventually used was to create a DirectorySearcher and apply a filter that uses the samaccountname. Here's a quick code example:

Code Snippet


string username = txtUsername.Text;
DirectoryEntry domain = new DirectoryEntry("LDAP://adserver");
DirectorySearcher searcher = new DirectorySearcher(domain);

searcher.Filter = "(samaccountname=" + username + ")";
SearchResult result = searcher.FindOne();

foreach (DictionaryEntry property in result.Properties)
{
Panel pnlResult = new Panel();
Label newLabel = new Label();
Label newValue = new Label();

newLabel.Text = property.Key + ": ";
newLabel.ID = property.Key.ToString();
newLabel.Font.Bold = true;

newValue.Text = GetProperty(result, property.Key.ToString());

pnlResult.Controls.Add(newLabel);
pnlResult.Controls.Add(newValue);

pnlResults.Controls.Add(pnlResult);
}

007DeeJay at 2007-9-3 > top of Msdn Tech,Visual Studio Tools for Office,Visual Studio Tools for Office...