I am looking to find the email address of the current notes client user who is logged in programmatically. Is there a way to do it ? I am accessing username with session but I need email address Thanks in advance.
Asked
Active
Viewed 1,012 times
2 Answers
3
From the Help database, part of an example for the getMailInfo method:
Dim session As New NotesSession
Dim db As NotesDatabase
Dim mynotesdir As NotesDirectory
Set mynotesdir = session.getDirectory("server name")
Dim homeserver As Variant
homeserver = mynotesdir.GetMailInfo(session.UserName, True) ' or EffectiveUserName
Msgbox "internetMailAddress: " + Cstr(homeserver(7))

D.Bugger
- 2,300
- 15
- 19
-
I am getting the email address even session.GetDirectory("") no server name. but I have to write muhammad.saleh@...com which is not my session user name its my email address Muhammad Saleh is my session name. but it gives me an error user not found in directory – Muhammad Saleh May 01 '20 at 07:29
-
Where is this code supposed to run? In an agent? Or in a Form or so? And what happens if you try your full hierarchical user name, i.e. "Muhammad Saleh/YourDomain" ? – D.Bugger May 01 '20 at 13:18
-
code is running on action button in inbox (existing mail application) – Muhammad Saleh May 03 '20 at 07:01
-
when I try my hierarchical name it give me an error on user not found in directory – Muhammad Saleh May 03 '20 at 07:02
-
I changed one line to just _Set mynotesdir=session.getDirectory()_ and it works on my Notes system. Do you have multiple address books on your server? If so, see Hogne's answer. – D.Bugger May 03 '20 at 09:44
-
after this today, When i save the email address with name muhammad saleh in people of domino admin it gives me the email address which I saved but I want to get email address without going into any directory from account log in information e.t.c actually m totally new to lotus notes development – Muhammad Saleh May 03 '20 at 10:03
-
The address book database (names.nsf on the server) _is_ the central registration for all users. If the Person document isn't filled in correctly, you'll never be able to get to the mail address. By default, when an SMTP mail arrives, a Domino server accepts multiple variations of a user's name as correct mail address, even when that user's Internet address isn't filled in. If the internet mail address comes back as empty, you can take the short name in _homeserver(4)_ as internet address. – D.Bugger May 03 '20 at 12:15
-
See also https://help.hcltechsw.com/domino/10.0.1/conf_settinguphowaddressesareresolvedoninboundandoutb_c.html – D.Bugger May 03 '20 at 12:19
-
D.bugger it worked for me. But I have a Question for you ? there is no other way to access email address I mean without going into directory if a user does not have name and email address in directory then what will happened ? thanks in advance – Muhammad Saleh May 05 '20 at 05:26
-
Ah, good. In the old days, Notes mail was just internal, and everyone's user name was also their mail address. Then there was SMTP, and Notes accepted incoming mail when it found the Internet mail addresses matched a unique user name, like muhammad.saleh@acme.com or even saleh.muhammad@acme.com. It was also possible to add a short ID to the Person document, or even a full mail address, to help Notes find a person and their mail database. Nowadays there is the Internet address. – D.Bugger May 05 '20 at 11:53
-
For outgoing mail, Notes also relies on the Address Book. It takes the Internet address, or the first entry in the short ID (I'm not quite sure here) and appends the server domain. But be careful, for a user can specify their own mail address in the Location document on their system. – D.Bugger May 05 '20 at 11:58
-
alright D.bugger bundle of thanks for your explanation and guidance – Muhammad Saleh May 06 '20 at 06:47
-
Neat solution, was not aware of the NotesDirectory; will see if I use this instead of @Hogne B. Pettersen "standard" approach in the future. – DonMaro May 11 '22 at 13:57
1
You will need to look up the e-mail address in the organisation's address book(s) (names.nsf).
Here is a slightly modified code from the Designer help,where you use s.Username use to search through the Address book(s) for the email address.
Sub Click(Source As Button)
Dim session As New NotesSession
Dim books As Variant
Dim view As NotesView
Dim doc As NotesDocument
Dim done As Variant
Dim person As String
books = session.AddressBooks
done = False
Forall b In books
' check every Domino Directory,
' unless we're already done
If ( b.IsPublicAddressBook ) And ( Not done ) Then
Call b.Open( "", "" )
' look up person's last name
' in People view of address book
Set view = b.GetView( "($People)" )
Set doc = view.GetDocumentByKey( session.Username )
' if person is found, display the email address
' from the Person document
If Not ( doc Is Nothing ) Then
Messagebox( "Email for " + person " is " + doc.InternetAddress( 0 ) )
done = True
End If
End If
End Forall
' if done is still False, the person wasn't found
If Not done Then
Messagebox( "Sorry, unable to locate person's email." )
End If
End Sub

Hogne B. Pettersen
- 11
- 2
-
This is a good solution for looking through all address books, but the key to match is the session.UserName, not just a last name, for which there could be multiple matches. – teleman Apr 30 '20 at 14:11
-
Yes, of course. I just wanted to give him an idea on how you could solve it by using the address book. Because that's what he needs to do here. He would of course need to use the full name.But I see D.Bugger's solution is much better. I didn't know about that one – Hogne B. Pettersen Apr 30 '20 at 18:47
-
Your solution checks all name and address books, D.Bugger's does not. Perhaps you can edit your solution to use the session.UserName -- no correct answer has been selected yet, and your first post could be it. ;-) – teleman Apr 30 '20 at 21:13
-
-
@MuhammadSaleh I've edited my code now to use s.UserName and a different view from the address book (you HAVE to use the address book to achieve this). Try it now – Hogne B. Pettersen May 03 '20 at 12:27