Run script on new e-mails

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.
 
LVL 8
HaydnHAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

madheeswarCommented:
U need to write an agent and the condition should be When New mail arrives.

What is ur exact requiremnt?
0
HaydnHAuthor Commented:
"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
qwaleteeCommented:
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
C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

qwaleteeCommented:
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
qwaleteeCommented:
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
HaydnHAuthor Commented:
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
madheeswarCommented:
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
madheeswarCommented:
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
HaydnHAuthor Commented:
hmmm... can I access a notes server using any other mail client? i.e: does the server support POP3/IMAP?
0
GoofytouyCommented:
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
madheeswarCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
qwaleteeCommented:
Ah, madheeswar, that should be:

LOAD POP3 to enable POP3
OAD IMAP to enable IMAP4
0
qwaleteeCommented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Lotus IBM

From novice to tech pro — start learning today.