none
Get user name or base address of account outlook RRS feed

  • Question

  • Hi,

    In my outlook add in, I want to get "user name" or "base address". But I just get "SmtpAddress". There are any way to get user name of user login outlook

    Monday, November 23, 2015 12:13 PM

All replies

  • Do you develop a COM add-in or Mail App?

    The CurrentUser property of the Namespace class returns the display name of the currently logged-on user as a Recipient object. For example:

    Sub DisplayCurrentUser()  
     Dim myNamespace As Outlook.NameSpace 
     Set myNameSpace = Application.GetNameSpace("MAPI")  
     MsgBox myNameSpace.CurrentUser  
    End Sub

    Monday, November 23, 2015 6:12 PM
  • But I want to get loginID of curent user. There are any way to get?
    Tuesday, November 24, 2015 2:07 AM
  • Do you need the profile name?

    You may find the Environment.UserName property which returns the user name of the person who is currently logged on to the Windows operating system. See How to get Windows Login credentials using C#.Net? for more information.

    Tuesday, November 24, 2015 10:54 AM
  • Thanks for your answer but I do not want current user  Windows, I want user of outlook. I can get smpt address but it can change so I need loginID
    Wednesday, November 25, 2015 9:18 AM
  • You may find the CurrentProfileName property of the Namespace or Application class helpful, it returns string representing the name of the current profile.
    Wednesday, November 25, 2015 9:48 AM
  • this property just show profile name but not show loginID
    Thursday, November 26, 2015 9:11 AM
  • What login ID are you looking for then? Could you please be more specific?

    The Outlook object model doesn't provide any login ID properties. 

    Thursday, November 26, 2015 10:40 AM
  • When your email is "abc@xyz.com", when you login OWA you will "xyz\abc", I tried to use username property but it did not show loginID of email.
    Monday, November 30, 2015 7:17 AM
  • >>>When your email is "abc@xyz.com", when you login OWA you will "xyz\abc", I tried to use username property but it did not show loginID of email.

    According to your description, you could use String Functions to search and manipulate strings, you could refer to below code:

    Function GetLoginID(strAddress As String) As String
        Dim intPos1 As Integer, intPos2 As Integer
        Dim userName As String, domain As String
        intPos1 = InStr(1, strAddress, "@")
        If intPos1 > 0 Then
            userName = Mid(strAddress, 1, intPos1 - 1)
            intPos2 = InStr(intPos1, strAddress, ".")
            domain = Mid(strAddress, intPos1 + 1, intPos2 - (intPos1 + 1))
            GetLoginID = domain & "\" & userName
        Else
            GetLoginID = strAddress
        End If
    End Function

    then could get LoginID like below:

    Dim mailAddress As String
    
    mailAddress = "john@yahoo.com"
    
    Debug.Print GetLoginID(mailAddress)

    For more information, click here to refer about String Functions (Visual Basic)

    Tuesday, December 1, 2015 9:37 AM
  • But a login ID can has a lot of email "domail\john" can has joinbaseaddress@yahoo.com and joinalias@yahoo.com or joinrealname@yahoo.com. Login ID and Email do not same.
    Thursday, December 3, 2015 3:06 AM
  • >>>when you login OWA you will "xyz\abc"

    Could you provide screenshot about how you use your login ID to login OWA? That will help us reproduce and resolve your issue!

    Thanks for your understanding.

    Friday, December 4, 2015 9:11 AM
  • This is screen OWA 

    screen same as image in this link (http://2.bp.blogspot.com/-Q_hKmvMSSWA/UIzJr25TkpI/AAAAAAAAIjQ/qJjhhPouk8U/s1600/Default+OWA+2013+Logon.png)

    I want to get this UserName in outlook. An account could has many email, but only one UserName.

    Thank for your answers.

    Monday, December 7, 2015 10:06 AM
  • >>>I want to get this UserName in outlook. An account could has many email, but only one UserName.

    As far as I know, Outlook Web Access doesn't have an object model you can work with, unlike Outlook itself.

    Friday, December 11, 2015 9:09 AM