Solved

Help with Agent Construction

Posted on 2004-09-20
10
235 Views
Last Modified: 2013-12-18
I have limited Notes scripting knowledge.
Can someone give me the steps to creating an agent that watches a mailbox for any message containing the text "CBS News" in the SUBJECT and then puts the BODY of that message in a file called "news.txt" on my C: drive.
Please be fairly specific.
thanks
0
Comment
Question by:rbender
10 Comments
 

Expert Comment

by:tsrconsultant
Comment Utility
First:  Create a new agent and in the agent properties, select under runtime --> Trigger (On Event) and select AFTER NEW MAIL HAS ARRIVED.

This agent will then automatically run right after mail has arrived in your mailbox.  Now, to the agent:

Sub Initialize
      Dim db As notesdatabase
      Dim session As New NotesSession
      Dim doc As notesdocument
      Dim collection As NotesDocumentcollection
      Dim mysearch As String
      Dim rt As NotesRichTextItem
      
      Set db=session.currentdatabase

      filen$="\home\john\news.txt"

      'get any emails that have not been processed -- usually just one
      Set collection=db.unprocesseddocuments
      For x=1 To collection.count
            Set doc=collection.getNthdocument(x)
            Set rt=doc.getFirstItem(body)
            'get the text of the body
            mysearch=rt.getUnformattedText
            If Instr(mysearch,"CBS News",5)>0 Then
                  'lets send this message to the hard drive
                  fileNum% = Freefile
                  whenNow$ = Today()
                  Open filen$ For Append As fileNum%
                  Print #fileNum%,"Entry Created on: "+whenNow$
                  Print #fileNum%,mysearch+Chr(0)
                  Close #fileNum%                  
            End If
      Next
End Sub


** The problem we have here is that the AGENT will run on the server, so you have two choices on getting access:

#1.  Have the domino program write a file in a shared space or your home directory on the server:  example: if your username is john and you are on a linux type server you would replace the filen$ above to:  "/home/john/news.txt" -- you also may need to get the admin to allow the user 'notes' to access your home directory.

#2.  Have your admin map a drive to a shared folder on your computer and update the filen$ to represent that.  Your admin should be able to provide you with the proper path.
0
 
LVL 31

Expert Comment

by:qwaletee
Comment Utility
Or, alternatively, keep a local replica of your mail file, and turn on the User Preference to allow local scheduled agents.  Then you can schedule the agnet to run on your PC.
0
 

Author Comment

by:rbender
Comment Utility
tsrconsultant:

The agent Initialize code won't get accepted.
Keeps alerting me and putting the cursor on :

      mysearch=rt.getUnformattedText


0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

Author Comment

by:rbender
Comment Utility
ping
0
 
LVL 7

Expert Comment

by:BarryTice
Comment Utility
Change the line to:
mysearch = rt.GetUnformattedText(False, 80)

That should work for you.

-- b.r.t.
0
 
LVL 7

Expert Comment

by:BarryTice
Comment Utility
Actually, the code above searches for "CBS News" in the body, not the subject. That's not what you wanted.

Try this code instead:

Sub Initialize
      Dim session As New NotesSession
      Dim db As NotesDatabase
      Dim dc As NotesDocumentCollection
      Dim doc As NotesDocument
      Dim item As NotesItem
      Dim rtItem As NotesRichTextItem
      Dim intFile As Integer
      Dim whenNow As String
      
      Set db = session.CurrentDatabase
      Set dc = db.UnprocessedDocuments
      Set doc = dc.GetFirstDocument
      
      whenNow = Today()
      
      Do While Not (doc Is Nothing)
            Set item = doc.GetFirstItem("Subject")
            If Instr(item.Text, "CBS News") > 0 Then
                  intFile = Freefile
                  Open "C:\CBS.txt" For Append As #intFile
                  Print #intfile, Chr$(13)      ' Carriage return
                  Print #intfile, "Data added " & whenNow
                  Set rtItem = doc.GetFirstItem("Body")
                  Print #intfile, rtItem.GetUnformattedText(False, 80)
                  Close #intfile
            End If
            Set doc = dc.GetNextDocument(doc)
      Loop
End Sub

As mentioned above, if your mail is on the server and you get permission to run it there, you're still going to have problems. Chief among these problems is that it won't know your C:\ drive from anybody else's. That, in and of itself, is enough reason to not take the "After Mail Arrives" approach for something like this, especially as getting updates from CBS News is _probably_ not part of your official job requirements, and having to do extra work for you to be able to do non-work-related stuff probably won't be high on your sysadmin's list. Or, work locally, as qwaletee suggests.

It might be easier (though certainly less automated) to have the above script in an agent that you run manually from the actions menu against All Unread Documents in View. Then you could run the script throughout the day as you see fit before going to look into the CBS.txt file for what Dan Rather is saying these days.

-- b.r.t.
0
 
LVL 7

Accepted Solution

by:
BarryTice earned 50 total points
Comment Utility
OK, my mistake (based on tsrconsultant's mistake): There is no GetUnformattedText method for a NotesRichTextItem. Use either rtItem.GetFormattedText(False, 80) to get the text formatted into 80-character lines, or rtItem.Text to get the raw text.

-- b.r.t.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

You’ve got a lotus Domino web server, and you have been told that “leverage browser caching” is a must do. This means that we have to tell the browser everywhere in the web to use cache. In other words, we set (and send) an expiration date in the HT…
This article covers general Notes 8.5 troubleshooting information including recreating the Notes\Data folder.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

771 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now