When New Mail Arrives In Lotus If Subject Contains A Specific Phrase Execute A File On The Network

Hello all, hopefully this is easy to understand.  What I would really like to do is setup an agent (if that is the approriate method) to do something if a email that comes to me has a specific phrase in the subject line.  If the phrase is a specific phrase as specified in the agent I want to execute a file on the network.  Watcha think?  Can it be done?  I am looking for some code examples to do this!  Thanks in advance.
jwebster77Asked:
Who is Participating?
 
SysExpertConnect With a Mentor Commented:
Use the shell command to run a progam

The following example is specific to Windows:
' Start the Windows Calculator as a normal (not minimized)
' window with focus.
Dim result As Integer
result = Shell("CALC.EXE",

-----

Syntax
Shell ( program [ , windowStyle ] )
Elements
program
A string expression whose value is the name of the program to run, including arguments. program can be the name of an executable file that uses a file name extension of BAT, COM, PIF, or EXE. You can omit the file name extension, and you can optionally include a complete path specification.
Using an internal DOS command name generates an error.
windowStyle
Optional. A number designating a valid window style, as specified in the following table.
Style      Description      Constant
1, 5, or 9      Normal with focus      SHELL_NORMAL_FOCUS
2       Minimized with focus (default)      SHELL_MIN_FOCUS
3       Maximized with focus      SHELL_MAX_FOCUS
4 or 8      Normal without focus      SHELL_NORMAL_NO_FOCUS
6 or 7      Minimized without focus      SHELL_MIN_NO_FOCUS
The constants are defined in the file lsconst.lss. Including this file in your script allows you to use constant names instead of the numeric values assigned to them.
Return value
If LotusScript successfully starts program, Shell returns the number 33.
Note  To get the program's task ID, use the Shellid function instead.
If LotusScript cannot start program, Shell returns an error.
Usage
Shell must be called from within an expression or an assignment statement, so that its return value is used.
In a UNIX or AIX environment, LotusScript will resume execution of the script only after the program has completed.  
In other environments, after Shell starts a program, LotusScript continues to execute the script without waiting to make sure the program has completed. You cannot be sure that a program started by Shell has finished running before the rest of your script is executed.
Language cross-reference

--------------

I hope this helps !
0
 
SysExpertCommented:
It can be done, the question is how best to do this.

I would set up a rule that puts the mail in a specific folder, and then run an agent  every 5 minutes, and check for an email in th folder, run your code, and move the doc out of that folder ad into some other folder.

I hope this helps !
0
 
jwebster77Author Commented:
I have this in my agent...  See the part below where the ----- are because that is where the action happens for what I want to do here.  Is the syntax right  I'm thinking maybe reading the subject line is incorrect

Sub Initialize
      Const sForward = "myblackberryaddress"
      
      Dim session As New NotesSession
      Dim note As NotesDocument
      Dim docNew As Notesdocument
      Dim db As NotesDatabase
      Dim item As NotesItem
      
      Set session = New NotesSession
      Set db = session.CurrentDatabase
      Set note = session.DocumentContext
      Set item = note.GetFirstItem("Body")
      
      Set docNew = New Notesdocument(db)
      docNew.Form = "Memo"
      Call item.copyitemtodocument(docNew, "")
      docNew.SendTo = sForward
      docNew.From = " " & note.From(0)
      docNew.Principal = " " & note.From(0)
      docNew.Subject = note.Subject(0)
      
      Call docNew.Send(True)
      
      If note.subject(0) = "REBOOT" Then
            Dim result As Integer
            result = Shell("\\AdminPC\OracleApps3Restart\OracleApps3Restart.bat",1)
      End If
      
End Sub
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
jwebster77Author Commented:
I have this in my agent...  See the part below where the ----- are because that is where the action happens for what I want to do here.  Is the syntax right  I'm thinking maybe reading the subject line is incorrect

Sub Initialize
      Const sForward = "myblackberryaddress"
     
      Dim session As New NotesSession
      Dim note As NotesDocument
      Dim docNew As Notesdocument
      Dim db As NotesDatabase
      Dim item As NotesItem
     
      Set session = New NotesSession
      Set db = session.CurrentDatabase
      Set note = session.DocumentContext
      Set item = note.GetFirstItem("Body")
     
      Set docNew = New Notesdocument(db)
      docNew.Form = "Memo"
      Call item.copyitemtodocument(docNew, "")
      docNew.SendTo = sForward
      docNew.From = " " & note.From(0)
      docNew.Principal = " " & note.From(0)
      docNew.Subject = note.Subject(0)
     
      Call docNew.Send(True)
      ------
      If note.subject(0) = "REBOOT" Then
            Dim result As Integer
            result = Shell("\\AdminPC\OracleApps3Restart\OracleApps3Restart.bat",1)
      End If
     
End Sub
0
 
qwaleteeCommented:
Code won't do what you want it to.  This doesn't say "tell the PC named AdminPC to run a file it has named oracle3appsrestart.bat."

What it does mean is "go retrueve the file oracleapps3restart.bat," and run that file on the computer that is running the agent.

To do what you want, you need to get a program that executes other programs remotely.  Mark Russinovich's PsTools suite includes a utility to do this.  Microsoft bought his company, so these are now Microsoft-provided free tools.

As to your search code, why bother? Set a agent to process new messages, create a condition on your agent taht matches the subject phrase, and your code will be as simple as:

Sub Initialize
   x = Shell("C:\Program Files\PsTools\PsExec \\AdminPC C:\OracleApps3Restart\OracleApps3restart.bat")
End Sub
0
 
jwebster77Author Commented:
I guess my questions becomes, how do I create a condition on an agent.  I agree, taht woudl be the easy way.
0
 
qwaleteeConnect With a Mentor Commented:
1) Full text index the database

2) In the agent screen click on DOCUMENT SELECTION

3) Click ADD CONDITION

4) Choose condition BY FIELD

5) Select field SUBJECT

6) Enter the phrase you are seartching for in "value"
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.