Solved

Run script on new e-mails

Posted on 2003-12-02
13
405 Views
Last Modified: 2013-12-18
Hi All,

I'm currently working on a project where the client uses wintel boxes using lotus notes. Coming from a unix background I am used to the delightful flexibility of procmail and shell scripting. I would like to use a similar method with Notes but I'm not sure where to look - can anyone tell me how you can run scripts (Lotus script??) on incoming mails?

i.e: is it possible to create a "rule" for new mails similar to the following pseudo code:

  If ("mail subject" = "some text" and "hasAttachment" = True) {
    Run a dos command on the mails attachment
  }

Note: Notes R5 on W2k pro

Thanks,

Haydn.
 
0
Comment
Question by:HaydnH
  • 5
  • 4
  • 3
  • +1
13 Comments
 
LVL 19

Expert Comment

by:madheeswar
Comment Utility
U need to write an agent and the condition should be When New mail arrives.

What is ur exact requiremnt?
0
 
LVL 8

Author Comment

by:HaydnH
Comment Utility
"U need to write an agent and the condition should be When New mail arrives"

How is this done? Where in Notes is it and what language is it written in?


"What is ur exact requiremnt?"

Basically I'm lazy - which is why I love programming =P

I get sent spreadsheets monthly (about 15 of them from different managers), I currently have a form in an access database which allows me to bundle all of the spreadsheets together, update the database from them and generate another spreadhsheet from the updated data in the database.

All of this could be run through a macro (currently run from vba) and as such I can run it from a command line ("msacces mydb.dbm /x mymacro").

What I wish to do is stop having to waste time going through the 15 spreadhseets and telling the database where they are... so I would like a script (agent??) in notes that:

    When new mail arrives...
                  |
                  |                                             |No
    Does it have the subject "My Subject"?  ------- Leave in InBox
                  |
                  |---- Yes
                  |
    Does it have an xls attachment? --------------- Mark as error (possibly mail manager)
                  |
                  |
    Save attachment to c:\somewhere\somefile.xls
    And run command line (as above)
                  |
                  |
    Move mail to completed folder


Haydn.
0
 
LVL 31

Expert Comment

by:qwaletee
Comment Utility
The process would have to run in teh same place you have the mail file.  Usually, mail files stay on the Domino server (Notes server).  But you probably DON'T want to put the file shares and teh other executable on the Domino server.  All kinds of security and performance issues with that.  If that isn't a concern, I can show you the simplest way to accomplish it.  If you are nervous (as I would be) about placing the sahres and executables on teh Domino server, I'll discuss a more complex solution with you.

Anyway, here's the "simple" version that runs on teh Domino server.

Install Designer f you don't already have it installed
Open mail file
Create -> Agent
Set to run before new mail arrives
Change from SIMPLE ACTION to LOTUSSCRIPT
Click on the INITIALIZE "event"
Here's your code:

CONST SubjectText = "My subject" 'must be an exact match, no leading or trailing characters, not even extra spaces
CONST ExtractPath = "c:\somewhere\somefile.xls" 'include path and file name
CONST commandLine = "c:\someplace\someprogram.exe"

Dim s as new notesSession
Dim db as notesDatabase
Set db = s.currentDatabase
Dim messages as notesDocumentCollection
Set messages = db.unprocessedDocuments
Dim msg as notesDocument, nextMsg as notesDocument
Set msg = messages.getFirstDOcument
Do Until msg is nothing
  Set nextMsg = messages.getNextMessage(ms) 'cache the next one in case we lose track of position due to a delete
  If msg.Subject(0) = SubjectText Then
    Dim xlsCheck
    xlsCheck = Evaluate({!""=@Trim(@Left(@UpperCase(@AttachmentNames);".XLS"))},msg)
    If xlsCheck(0) = "0"
      msg.Subject = "***MISSING EXCEL FILE***" & doc.Subject(0)
    Else
      Dim fileName
      fileName = Evaluate({@Trim(@Left(@UpperCase(@AttachmentNames);".XLS"))},msg)
      Dim attachment as notesEmbeddedObject
      Set attachment = doc.getAttachment(fileName(0))
      If attachment is nothing Then
        msg.Subject = "***COULD NOT RETRIEVE EXCEL FILE***" & doc.Subject(0)
      Else
        attachment.extractFile ExtractPath
        Dim shellReturn as Long
        shellReturn = SHell(commandLine)
        msg.moveToFlder "Completed"
      End If
    End If
  End If
  Set msg = nextMsg 'retrieve from cache
Loop
0
 
LVL 31

Expert Comment

by:qwaletee
Comment Utility
Oops!  typos alert

    If xlsCheck(0) = "0" ->     If xlsCheck(0) = "0" Then


            Set nextMsg = messages.getNextMessage(ms) 'cache the next one in case we lose track of position due to a delete
->               Set nextMsg = messages.getNextDocument(msg) 'cache the next one in case we lose track of position due to a delete

                        msg.Subject = "***MISSING EXCEL FILE***" & doc.Subject(0)
->                          msg.Subject = "***MISSING EXCEL FILE***" & msg.Subject(0)

                        Set attachment = doc.getAttachment(fileName(0))
->                          Set attachment = msg.getAttachment(fileName(0))


                              msg.Subject = "***COULD NOT RETRIEVE EXCEL FILE***" & doc.Subject(0)
->                                msg.Subject = "***COULD NOT RETRIEVE EXCEL FILE***" & msg.Subject(0)

        msg.moveToFlder "Completed" ->         msg.moveToFolder "Completed"

0
 
LVL 31

Expert Comment

by:qwaletee
Comment Utility
WIth above corrections incorporated:
      Const SubjectText = "My subject" 'must be an exact match, no leading or trailing characters, not even extra spaces
      Const ExtractPath = "c:\somewhere\somefile.xls" 'include path and file name
      Const commandLine = "c:\someplace\someprogram.exe"
      
      Dim s As New notesSession
      Dim db As notesDatabase
      Set db = s.currentDatabase
      Dim messages As notesDocumentCollection
      Set messages = db.unprocessedDocuments
      Dim msg As notesDocument, nextMsg As notesDocument
      Set msg = messages.getFirstDOcument
      Do Until msg Is Nothing
            Set nextMsg = messages.getNextDocument(msg) 'cache the next one in case we lose track of position due to a delete
            If msg.Subject(0) = SubjectText Then
                  Dim xlsCheck
                  xlsCheck = Evaluate({!""=@Trim(@Left(@UpperCase(@AttachmentNames);".XLS"))},msg)
                  If xlsCheck(0) = "0" Then
                        msg.Subject = "***MISSING EXCEL FILE***" & msg.Subject(0)
                  Else
                        Dim fileName
                        fileName = Evaluate({@Trim(@Left(@UpperCase(@AttachmentNames);".XLS"))},msg)
                        Dim attachment As notesEmbeddedObject
                        Set attachment = msg.getAttachment(fileName(0))
                        If attachment Is Nothing Then
                              msg.Subject = "***COULD NOT RETRIEVE EXCEL FILE***" & msg.Subject(0)
                        Else
                              attachment.extractFile ExtractPath
                              Dim shellReturn As Long
                              shellReturn = Shell(commandLine)
                              msg.moveToFolder "Completed"
                        End If
                  End If
            End If
            Set msg = nextMsg 'retrieve from cache
      Loop
0
 
LVL 8

Author Comment

by:HaydnH
Comment Utility
OK... I'm working in a council office for this project, and as such the IT dept are a little 'protective' about their servers (read: they don't want any extra work!), so:

 - The script has to be run on the workstation when reading mail - not the server
      ... because I can't access the servers
      ... and the script will have to run on a machine with access installed

 - We don't have designer and I assume it cost's $$$ - the council has no budget for me!

Is this still possible? If not I'm beginning to hate notes more and more each day!

Haydn.
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 19

Expert Comment

by:madheeswar
Comment Utility
all the mails coming in to inbox are on server.

if u want to run agent on incoming emails means, u have to keep that agent on server.

Locally if u replicate also, the document is already in the inbox on server database.

So, as I think it is not possible without altering template. U have to adjust like that.

0
 
LVL 19

Expert Comment

by:madheeswar
Comment Utility
and without extra work it is not possible. even they can't spend money for any 3rd party softwares.

If u want to achieve some thing, u have to choose any of the above options.

Spend money or allot some time to do extra work.

For designer u need to spend money. And u need one designer to implement it.

One more time I am telling:
To run on incomng emails which are coming from server, u need to run agent on the server.

Else:
Qwaletee:
Can we run that agent from any other application to look into inbox of the person and when it came, then do the necessary things?
What do u say Qwaletee?

A lost hope is to run agent from another database. For this also, u need designer.
0
 
LVL 8

Author Comment

by:HaydnH
Comment Utility
hmmm... can I access a notes server using any other mail client? i.e: does the server support POP3/IMAP?
0
 
LVL 5

Expert Comment

by:Goofytouy
Comment Utility
haydnH

The Domino family servers support POP3/IMAP, but they must be enabled (subapp running).
You may speak to your IT dept and ask if the domino server is reachable with programs like Outlook.



0
 
LVL 19

Accepted Solution

by:
madheeswar earned 250 total points
Comment Utility
load smtp is the command which u have to type at server console. This will enable POP3

But, u have to know the pros and cons once u enable this.
0
 
LVL 31

Expert Comment

by:qwaletee
Comment Utility
Ah, madheeswar, that should be:

LOAD POP3 to enable POP3
OAD IMAP to enable IMAP4
0
 
LVL 31

Assisted Solution

by:qwaletee
qwaletee earned 250 total points
Comment Utility
HaydnH,
> hmmm... can I access a notes server using any other mail client? i.e: does
> the server support POP3/IMAP?

You can run the agent locally by making a local replica.  As I mentioned, it would have to be set to "new documents" instead of "when mail is delievered."  There really would not be much difference in the way it performs, and the code would be identical.

You can also have Access do the scripting.  The Notes object model is available via COM.  So, most of that script could go straight into VBA.  It could access the server data, whiel executing teh code on a workstation.

If you want to create agents (native Notes processing), you would definitely need Designer.  Only very basic agents are supported without Designer.  You can doanload the Designer trial from notes.net.

0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

For Desktop Techs: How to retain a user's Notes configuration data when swapping out the end user's computer. (Assuming that you are not upgrading to a completely different version of Notes client) All you need to do is: 1) install Notes o…
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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

763 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

8 Experts available now in Live!

Get 1:1 Help Now