How to get full name of the owner of mail file in Lotus Notes
-
20-09-2019 - |
Question
Provided that I have the mail file name and the server, how do I retrieve the fully qualified name of the user it corresponds to in the form "CN=xxx/O=yyy" using LotusScript?
To start with, I have the user's username - the part before @ in the email: i.e. user1@example.com
I also know server, on which this user is registered, so I use Registration.GetUserInfo like this:
Dim reg as New NotesRegistration
reg.RegistrationServer = "CN=myserver/O=mydomain"
Call reg.GetUserInfo("user1", mailserver$, mailfile$)
The question is: how out of this data I can get the full name of the user?
Solution 4
I ended up with this solution (as I know which is the AddressBook server for the user):
macro$ = { @DbLookup( "" ; "} & regServer & _
{" : "names.nsf" ; "($Users)" ; "} & shortName & {" ; "FullName" ) }
Dim namelist As Variant
namelist = Evaluate ( macro$ )
commonName = namelist(0)
OTHER TIPS
Here's a quick implementation of Jonesys suggestion:
Function getMailFileUser(mailserver As String, mailfile As String) As String
On Error Goto errorthrower
Dim session As New notessession
Dim dd As NotesDatabase
Forall candidate_dd In session.AddressBooks
If candidate_dd.Server<>"" And candidate_dd.IsPublicAddressBook Then
Set dd = candidate_dd
Exit Forall
End If
End Forall
If dd Is Nothing Then Error 1978,"Failed to find Domino Directory"
If Not dd.IsOpen Then Call dd.Open("","")
Dim userdocs As NotesDocumentCollection
Set userdocs = dd.Search({form="Person" & }& _
{@name([CANONICALIZE];MailServer)=@name([CANONICALIZE];"} & mailserver & {") & } &_
{MailFile="} & mailfile & {"},Nothing,1)
Dim userdoc As NotesDocument
Set userdoc = userdocs.GetFirstDocument
If Not userdoc Is Nothing Then
getMailFileUser = userdoc.FullName(0)
Else
getMailFileUser=""
End If
Exit Function
ErrorThrower:
Error Err, Error & Chr(13) + "Module: " & Cstr( Getthreadinfo(1) ) & ", Line: " & Cstr( Erl )
End Function
A few words of caution:
CANONICALIZE
picks its values from the current ID, not the domino directory - the inputmailserver
must be in either abbreviated or canonicalized form for this to work.- The
MailFile
field may or may not include the.nsf
extension. - I don't think the file name is case sensitive on Windows, but it might be on other platforms.
If you need to do these lookups frequently, a computed lookup table or a view in the Domino Directory is probably the most efficient solution.
If you have the mail file name, why not do a lookup into the NAB using that as your key and get the full name that way?
If you have the internet address you can just use the NotesName class.
Dim s As New NotesSession
Dim userName As NotesName
Dim canonicalName as String
Set userName = s.CreateName("user@yourdomain.com")
'You can use the previous line or the next line to get the NotesName object
'Set userName = new NotesName("user@yourdomain.com")
canonicalName = userName.Canonical