none
Email Address of the Current User

    Question

  • 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

     

    Monday, July 31, 2006 9:11 AM

Answers

  • 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

    Monday, July 31, 2006 6:15 PM
    Moderator
  • Outlook 2007 will return the SMTP address, even for Exchange users.
    Thursday, August 03, 2006 1:51 AM
    Moderator

All replies

  • 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 > > > >
    Monday, July 31, 2006 2:09 PM
  • 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

    Monday, July 31, 2006 6:15 PM
    Moderator
  • 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

     

    Wednesday, August 02, 2006 8:31 AM
  • Outlook 2007 will return the SMTP address, even for Exchange users.
    Thursday, August 03, 2006 1:51 AM
    Moderator
  • 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
    Wednesday, October 11, 2006 10:05 AM
  • 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.

    Tuesday, May 29, 2007 8:48 PM
  •  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.

    Wednesday, May 30, 2007 4:00 PM
  • Is there a quick way to do this in .NET 2.0 (C#)?
    Wednesday, June 27, 2007 10:04 PM
  • 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.
    Wednesday, June 27, 2007 10:08 PM
    Moderator
  • 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);
                }


    Friday, July 06, 2007 1:11 PM
  • It's a little hacky, but if you are only using this for an outlook that has only one account, you can do something like this...

     

    currentExplorer.Session.Accounts[1]..SmtpAddress;

     

    Where currentExplorer is your application explorer of course..

     

    You can pass in the AccountName as an optional string instead of grabbing the first instance, if you know that value.

    Friday, May 07, 2010 5:38 PM
  • Yes, based on that...

    Outlook.AddressEntry currentUser = Application.Session.CurrentUser.AddressEntry;
    foreach (Microsoft.Office.Interop.Outlook.Account acct in Application.Session.Accounts)
    {
        if (acct.CurrentUser.Address == currentUser.Address)
        {
            email_from = acct.SmtpAddress;
            break;
        }
    }


    .Net thingy maker type guy.

    Thursday, July 05, 2012 4:23 PM