?
Solved

VBScript - lotus email

Posted on 2010-01-12
17
Medium Priority
?
1,559 Views
Last Modified: 2013-12-18
Hi,
I have the following code to check email on lotus notes:
Dim Maildb
Dim UserName ' The current users notes name
Dim MailDbNameCurr ' THe current users notes mail database name
Dim Session  ' The notes session
'Dim pin
Dim uiWorkspace  ' The Notes Workspace



Set Session = CreateObject("Notes.NotesSession")

 
Set uiWorkspace = CreateObject("Notes.NotesUIWorkspace")
Server = Session.GetEnvironmentString("MailServer",True)


 'login as admin  
 Call openMail("mail/admin.nsf")
 

' Calculate the mail file name
'MailDbNameCurr = "mail\PT105_"& Right(pin,2)&".nsf"
'then call it
 'Call openMail(MailDbNameCurr)

' Open the mail database in notes

Sub openMail(MailDbName)
Set Maildb = Session.GETDATABASE(Server, MailDbName)
  Maildb.OPENMAIL
If Maildb.IsOpen = True Then
' Already open for mail
   Else
   Maildb.OPENMAIL
   End If
End Sub

I get the following error:
User CN=...... cannot open database CN=......

Please help..Thanks
0
Comment
Question by:priyamB
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 6
  • 4
17 Comments
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 26294254
Where does this code run, client or server side?

Let's assume client side. Did you check the value of MailServer? Do you have the rights to open mail/admin.nsf?

Look in the log.nsf database on the server, in the Misc section; it will show the error message and the reason more clearly.
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 26294384
By the way, in general it is better to use COM and not OLE.
See http://www-01.ibm.com/support/docview.wss?rs=0&uid=swg21088358
0
 
LVL 22

Expert Comment

by:Bill-Hanson
ID: 26295720
Actually, I've had problems using the COM library in a VBScript shell (especially under 64 bit), so I would stick with OLE for this one.

priyamB, First, the simple stuff...

Are you sure that the server and file are correct and are you sure that the current user has access to the file?

Other than that, the error message is a bit strange in that it identifies the database using a CN component.  Can you post the entire message?

Your code looks OK, but just in case, here's a simple example that reads the subject from the first email in your inbox.
Dim sess
Set sess = CreateObject("Notes.NotesSession")

Dim db
Dim mailServer, mailFile
mailServer = sess.GetEnvironmentString("MailServer", True)
mailFile = sess.GetEnvironmentString("MailFile", True)
Set db = sess.GetDatabase(mailServer, mailFile, False)

Dim view
Set view = db.GetView("($Inbox)")

Dim doc
Set doc = view.GetFirstDocument()

wscript.echo(doc.GetFirstItem("Subject").Text)

Open in new window

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:priyamB
ID: 26295867
@Bill..i get the same error when i use your script..i started using lotus only yesterday so im not really sure how to give permission etc...i have attached a screenshot of the error
error.JPG
0
 
LVL 22

Expert Comment

by:Bill-Hanson
ID: 26296121
It looks like you are trying to use the server's id.  Server ids are not allowed to open databases (except by the actuall server, of course).  Does the Notes Client actually let you log in using a server id?
0
 

Author Comment

by:priyamB
ID: 26296186
im sorry for the noob questions but im not sure where im using the server id...i used ur script too with the same error..how would i check if i can log in using the server id?...the server and client are on the same VM btw
0
 

Author Comment

by:priyamB
ID: 26297345
ok so ive got the code to work for 1 user at a time:

'Sub notecheck(thisuser)

Dim Maildb
Dim Calendar
Dim Body
Dim Session
Dim thisUser
Dim maiDbName

Set Session = CreateObject("Lotus.NotesSession")
Set uiWorkspace = CreateObject("Notes.NotesUIWorkspace")
Call Session.Initialize("password")
thisUser= "01"
mailDbName="mail/PT105_" & thisUser & ".nsf"
Set Maildb = Session.GETDATABASE("PT105DOMVM01/PERKTEST",mailDbName)
If Not Maildb.IsOpen = True Then
Call Maildb.Open
End If

'End Sub

Right now it works only if thisUser ="01"
I want it to work as a subroutine for the value of thisUser ranging from 1 to 50..for any value that i put for thisUser other than '1' i get the same error as before..but it works fine for thisuser=1..any ideas?
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 26298640
To open a mail database as a user, you need the owner's permission, or you need to be added to the mail database's Access Control List. The Access Control List (or ACL) is a per database list of all people and groups who have access rights to the database. Access rights range from No Access, via Reader and Author to Manager (highest). Often, a user is Manager of his own mail database and no other user is allowed to enter. To grant access to a Domino server, each user will need his own ID-file and his own password to identify him/herself. Usually, that is exactly what you want: the current user of a PC can open his personal mail database.

If you want to open a specific user's mail database other than your own, you need that user's credentials on the PC. Plus, you have indicate that that user is the current user. The latter is pretty difficult to do from VBscript, if not impossible. The other way to get it done is by adding one person or group to every mail database, with Reader, Author or Editor rights (depending on what that person or group wants to do). Technically absolutely possible, for example the Administrator of the server could adopt your application.

Now, if I were a user in your company and I knew that there is an application that monitors my mail (or fiddles around with it), I'd call for legal help.

What exactly do you want to do??
0
 

Author Comment

by:priyamB
ID: 26299452
i am doing an internship project with a company(which i probably shouldnt name) wherein one of the steps involved is simulating the process of sending mails from a set of test users to one or more of other test users..currently that is done manually on a simulator with a gui and i need to automate the process..so these are not real users but just test .id(and their respective .nsf ) files that i have access to..i know their passwords(which are all the same)..i have the script as above..i need it to work for all 50 test users just by changing the value of the testUser variable
0
 
LVL 22

Expert Comment

by:Bill-Hanson
ID: 26303237
If you need to access 50 .nsf files, then you need to be listed in the ACL for each individual database.  It is too difficult to write a Notes OLE or COM client app that switches user ids (Especially OLE).  It is easy to do if you are running a COM app on a Domino server, but you aren't, so the easiest solution is to ensure that your ID has access to the 50 mail files.
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 26303475
And how come you chose VBscript? And not LotusScript?
0
 

Author Comment

by:priyamB
ID: 26304095
i was awarded the internship based on my VBScript nowledge..i had no idea what lotusscript is until yesterday..it seems identical to VBScript though
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 26304257
The languages are not identical, but quite similar. Here's why I asked: instead of programming 50 different startups you could add functionality to the mail template of the test databases, so that they all share the same code. You can access the user's database without knowing the name of the database (can also be done from VBscript).

On the other hand, this would test the Notes client and not only the lower levels. And a simulation with random mails is less easy.
0
 

Author Comment

by:priyamB
ID: 26306418
"you could add functionality to the mail template of the test databases, so that they all share the same code"..hmm..once again dont know how to do that :(

this is what i have right now:

Dim thisUser
Dim Maildb
Dim Calendar
Dim Body
Dim Session

Dim maiDbName
Dim notesSession

Set Session = CreateObject("Lotus.NotesSession")
Call Session.Initialize("shock")
Set uiWorkspace = CreateObject("Notes.NotesUIWorkspace")

'call admin db
call notecheck("admin")

count = 1 to 9
    thisUser = "0" & CStr(count)
      notecheck(thisUser)




Sub notecheck(thisuser)



If thisUser="admin" then
mailDbName="mail/admin.nsf"
else
mailDbName="mail/PT105_" & Right(thisUser,2) & ".nsf"
end if

Set Maildb = Session.GETDATABASE("PT105DOMVM01/PERKTEST",mailDbName)
If Not Maildb.IsOpen = True Then
Call Maildb.Open
End If


End Sub


the thing is it shows up on the mail server console that the db was accessed but the inbox doesnt open up on notes..i tried getview but it gives me an error

 



0
 
LVL 46

Accepted Solution

by:
Sjef Bosman earned 1500 total points
ID: 26306777
No, that's not the way you should go about this. You'd better open the current user's mail database WITHOUT knowing his name.

Here's code from the Help database:
Private Sub OpenMail_Click()
Dim s As New NotesSession
s.Initialize
Dim dir As NotesDbDirectory
Dim db As NotesDatabase
Set dir = s.GetDbDirectory("")
Set db = dir.OpenMailDatabase
MsgBox db.Title & " on " & db.Server, , db.FilePath
End Sub

Open in new window

0
 

Author Closing Comment

by:priyamB
ID: 31676134
Thanks
0
 
LVL 22

Expert Comment

by:Bill-Hanson
ID: 26309255
Essentially the same code I posted in #26295720.    :(
0

Featured Post

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lack of Storage capacity is a common problem that exists in every field of life. Here we are taking the case of Lotus Notes Emails, as we all know that we are totally depend on e-communication i.e. Emails. This article is fully dedicated to resolvin…
This article covers general Notes 8.5 troubleshooting information including recreating the Notes\Data folder.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question