Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Read Notes 7.0.3 mail with VB^

Posted on 2010-01-08
10
Medium Priority
?
465 Views
Last Modified: 2013-12-18
Running Notes 7.0.3

I need to be able to read the messages in the In Box (subject and body) then mark that item as read.  I have looked through the examples here and have tried them but seem to have one issue or another with each of them.
0
Comment
Question by:MERCOMMS
  • 5
  • 5
10 Comments
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 26216744
Can you show the code you tried mentioning the issue(s) you had?
0
 

Author Comment

by:MERCOMMS
ID: 26283572
I get an error "invalid use of New keyword "  on:

Set appNotes = New NOTESSESSION

I do have references to Lotus Notes Automation Classes and Lotus Domino Objects
    Dim appNotes As NOTESSESSION
    Set appNotes = New NOTESSESSION
    Dim dbNotes As NOTESDATABASE
    appNotes.Initialize
    Set dbNotes = appNotes.GETDATABASE(".", "Mail\sregistr.nsf")
    Dim vwInbox As NOTESVIEW
    Set vwInbox = dbNotes.GETVIEW("$Inbox")
    Dim docMessage As NOTESDOCUMENT
    On Error Resume Next
    With vwInbox
        Set docMessage = .GETLASTDOCUMENT
        Do
            If docMessage.ISNEWNOTE Then
                List1.AddItem "*  " & Join(docMessage.GETITEMVALUE("Subject"))
            Else
                List1.AddItem Join(docMessage.GETITEMVALUE("Subject"))
            End If
            Set docMessage = .GETPREVDOCUMENT(docMessage)
            DoEvents
        Loop Until docMessage Is Nothing
    End With
    Set docMessage = Nothing
    Set vwInbox = Nothing
    Set dbNotes = Nothing
    Set appNotes = Nothing

Open in new window

0
 

Author Comment

by:MERCOMMS
ID: 26284063
I added domino. to the lines I was getting errors and it now gets past those but now I get "Database !!Mail\sregistr.nsf has not been opened yet" on

"Set vwInbox = dbNotes.GETVIEW("$Inbox")



    Dim appNotes As domino.NOTESSESSION
    Set appNotes = New domino.NOTESSESSION
    Dim dbNotes As domino.NOTESDATABASE
    appNotes.Initialize
    Set dbNotes = appNotes.GETDATABASE(".", "Mail\sregistr.nsf")
    Dim vwInbox As domino.NOTESVIEW
    Set vwInbox = dbNotes.GETVIEW("$Inbox")
    Dim docMessage As NOTESDOCUMENT
    On Error Resume Next
    With vwInbox
        Set docMessage = .GETLASTDOCUMENT
        Do
            If docMessage.ISNEWNOTE Then
                List1.AddItem "*  " & Join(docMessage.GETITEMVALUE("Subject"))
            Else
                List1.AddItem Join(docMessage.GETITEMVALUE("Subject"))
            End If
            Set docMessage = .GETPREVDOCUMENT(docMessage)
            DoEvents
        Loop Until docMessage Is Nothing
    End With
    Set docMessage = Nothing
    Set vwInbox = Nothing
    Set dbNotes = Nothing
    Set appNotes = Nothing

Open in new window

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 46

Accepted Solution

by:
Sjef Bosman earned 1000 total points
ID: 26284188
Thanks for the code!

This line
    Set dbNotes = appNotes.GETDATABASE(".", "Mail\sregistr.nsf")
says:
      open database Mail\sregistr.nsf on server .
Things to look into:
- is there a server "." ??
- does that database exist?
- do you have sufficient rights to open the database?

I assume there is no server with the name ".", for that name is not acceptable by Domino as a server name. If you want to open a local database, use
    Set dbNotes = appNotes.GETDATABASE("", "Mail\sregistr.nsf")

By the way, what is the idea behind the code at line 13, the IsNewNote??
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 26284352
And there are several other mistakes in the code, for instance: what will happen when the Inbox is empty? And line 9 I'd leave out altogether, most error occur for a reason and are not to be ignored.
0
 

Author Comment

by:MERCOMMS
ID: 26284744
This is code I copied from another question here and am just tweaking it to serve my purposes.

Changing "." to "" resolved the last issue.  

Removed line 9

I am guessing that line 13 makes it only read messages that have not been viewed yet.

No errors are generated but strSubject = docMessage.GETITEMVALUE("Subject") returns empty
    Dim strSubject As String
    Dim appNotes As domino.NOTESSESSION
    Set appNotes = New domino.NOTESSESSION
    Dim dbNotes As domino.NOTESDATABASE
    
    
    appNotes.Initialize
    Set dbNotes = appNotes.GETDATABASE("", "Mail\sregistr.nsf")
    Dim vwInbox As domino.NOTESVIEW
    
    Set vwInbox = dbNotes.GETVIEW("$Inbox")
    Dim docMessage As domino.NOTESDOCUMENT

    With vwInbox
        Set docMessage = .GETLASTDOCUMENT
        Do
            If docMessage.ISNEWNOTE Then
                strSubject = docMessage.GETITEMVALUE("Subject")
            End If
            Set docMessage = .GETPREVDOCUMENT(docMessage)
            DoEvents
        Loop Until docMessage Is Nothing
    End With
    Set docMessage = Nothing
    Set vwInbox = Nothing
    Set dbNotes = Nothing
    Set appNotes = Nothing

Open in new window

0
 

Author Comment

by:MERCOMMS
ID: 26285711
Found something somewhere else.  The only thing it did not do is mark the messages read so the code would process every message every time.  To avoid this I created a notes folder and then move them to that folder with PUTINFOLDER and REMOVEFROMFOLDER
    Dim n_Session As New domino.NOTESSESSION
    Dim n_Database As New domino.NOTESDATABASE
    Dim n_View As New domino.NOTESVIEW
    Dim n_ViewNav As domino.NOTESVIEWNAVIGATOR
    Dim n_ViewEntry As domino.NOTESVIEWENTRY
    Dim n_Document As domino.NOTESDOCUMENT
    Dim strSubject As String
    Dim strBody As String

    Call n_Session.Initialize

    Set n_Database = n_Session.GETDATABASE("", "Mail\sregistr.nsf")
    Set n_View = n_Database.GETVIEW("($Inbox)")
    Set n_View = n_Database.GETVIEW("($All)")
    Set n_ViewNav = n_View.CREATEVIEWNAV
    Set n_ViewEntry = n_ViewNav.GETFIRSTDOCUMENT()

    Do While Not (n_ViewEntry Is Nothing)
        Set n_Document = n_ViewEntry.DOCUMENT
        strSubject = n_Document.GETITEMVALUE("Subject")(0)
        strBody = n_Document.GETITEMVALUE("Body")(0)
        n_Document.PUTINFOLDER "Old"
        n_Document.REMOVEFROMFOLDER "$Inbox"
        Set n_ViewEntry = n_ViewNav.GETNEXTDOCUMENT(n_ViewEntry)
    Loop
    
    GetMail = True
    Set n_ViewEntry = Nothing
    Set n_ViewNav = Nothing
    Set n_View = Nothing
    Set n_Document = Nothing
    Set n_Database = Nothing
    Set n_Session = Nothing

Open in new window

0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 26288230
Good! Code looks okay, well, most of it.

In this last piece of code, I don't get line 14. Now all messages are processed again and again, because (I assume) the $All view is a real view and not a folder. But you must have found that out by now, I hope. I also suppose you're going to do something with the values retrieved in lines 20 and 21.

And thanks for the grade!
0
 

Author Comment

by:MERCOMMS
ID: 26306548
Yes.  Had to take line 14 out.  Line 14 negated line 13 and was reading all documents instead of just the ones in the Inbox.  

Yes I am doing something with the values from 20 and 21.  I know how to do that though.

Thanks.
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 26306808
Okay! :-))
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

For beginners of Lotus Notes user this is important to know about the types of files and their location supported by IBM Notes. Mostly users are unaware about how many file types are created and what their usages are. This Article is fully dedicated…
Sometimes clients can lose connectivity with the Lotus Notes Domino Server, but there's not always an obvious answer as to why it happens.   Read this article to follow one of the first experiences I had with Lotus Notes on a client's machine, my…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

578 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