• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1675
  • Last Modified:

VBScript - lotus email

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
priyamB
Asked:
priyamB
  • 7
  • 6
  • 4
1 Solution
 
Sjef BosmanGroupware ConsultantCommented:
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
 
Sjef BosmanGroupware ConsultantCommented:
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
 
Bill-HansonCommented:
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!

 
priyamBAuthor Commented:
@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
 
Bill-HansonCommented:
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
 
priyamBAuthor Commented:
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
 
priyamBAuthor Commented:
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
 
Sjef BosmanGroupware ConsultantCommented:
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
 
priyamBAuthor Commented:
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
 
Bill-HansonCommented:
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
 
Sjef BosmanGroupware ConsultantCommented:
And how come you chose VBscript? And not LotusScript?
0
 
priyamBAuthor Commented:
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
 
Sjef BosmanGroupware ConsultantCommented:
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
 
priyamBAuthor Commented:
"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
 
Sjef BosmanGroupware ConsultantCommented:
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
 
priyamBAuthor Commented:
Thanks
0
 
Bill-HansonCommented:
Essentially the same code I posted in #26295720.    :(
0

Featured Post

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!

  • 7
  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now