Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Creating a Agent

Posted on 2008-10-06
20
528 Views
Last Modified: 2013-12-18
I had a question on here some time ago about creating a agent.  The agent is suppose to create a email from parsing some information from a incoming email document.  Here is the code I am trying to use.

Call SendMemoFromTag(memo, "username", Chr(10))

To be honest this may work.  But it has been so long since I have created a agent I am having problems with it.   Can someone help me create a agent using the code.

Thanks
Sub SendMemoFromTag(memo As NotesDocument, Byval tagStart As String, Byval tagEnd As String)
	
	Dim sess As New NotesSession
	Dim parts As Variant
	Dim body As String, sendto As String
	sess.ConvertMime = True
	body = memo.GetItemValue("Body")(0)
	If (Instr(1, body, tagStart, 5) = 0) Then Exit Sub
	parts = Split(body, tagStart)
	If (Instr(1, parts(1), tagEnd, 5) = 0) Then sendto = Trim(parts(1)) Else sendto = Trim(Strleft(parts(1), tagEnd))
	
	Dim memo2 As NotesDocument
	Set memo2 = memo.ParentDatabase.CreateDocument
	memo2.Form = "memo"
	memo2.Subject = "TEST"
	memo2.SendTo = sendto
	Call memo2.Send(False)
	
End Sub

Open in new window

0
Comment
Question by:Jaziar
  • 10
  • 10
20 Comments
 
LVL 22

Expert Comment

by:mbonaci
ID: 22653082
It will work if the incoming e-mail body string parsing is done OK.
Test it.
Or specify the format of incoming e-mails so we can determine whether the address pulling is done the right way.

Hope this helps,
Mb¤
0
 

Author Comment

by:Jaziar
ID: 22653176
I can't get the agent to save to test it.  I am not sure how to set up the agent.
0
 
LVL 22

Expert Comment

by:mbonaci
ID: 22653183
Aha, you also want help with agent creation.
In Designer - New Agent.
Trigger: On Event - After new mail has arrived.

Since the target is "Newly received mail documents" that means that when you get the Unprocessed documents collection from your db it will consist of those new e-mails. All you have to do is go through them using loop, like this:

(place it in the agent's initialize event. Also paste the function SendMemoFromTag in the agent)

Dim s As New NotesSession
Dim db As NotesDatabase
Dim c As NotesDocumentCollection
Dim cur As NotesDocument
 
Set db = s.CurrentDatabase
Set c = db.UnprocessedDocuments
 
Set cur = c.GetFirstDocument
Do Until cur Is Nothing
	
	Call SendMemoFromTag( cur, "username", Chr(10) )
	Set cur = c.GetNextDocument( cur )
Loop

Open in new window

0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

 
LVL 22

Expert Comment

by:mbonaci
ID: 22653192
I can read your mind :)
0
 

Author Comment

by:Jaziar
ID: 22653324
I wish you could teach that trick to my wife :)
0
 
LVL 22

Expert Comment

by:mbonaci
ID: 22653365
I presume it works (since you're comparing it with your wife)?

Or you want to say that it doesn't work :)
0
 

Author Comment

by:Jaziar
ID: 22653393
It works when I run the agent from the action menu selection but not when I have it set to After new mail has arrived.
0
 

Author Comment

by:Jaziar
ID: 22653718
OK I can set this up to run every 5 minutes and it works great.  Is there a way to place a line in the loop that will mark the email as read once it has been used by the agent?

Example

Do Until cur Is Nothing
       
        Call SendMemoFromTag( cur, "username", Chr(10) )
         cur = read <===================================        
Set cur = c.GetNextDocument( cur )
Loop

So that when the next time the agent runs it only gets the new documents
0
 
LVL 22

Expert Comment

by:mbonaci
ID: 22653934
You don't want to do it that way, trust me.

Lets make sure, your db (where you created the agent in) is the db that receives e-mails, isn't it?

Is your db on a server? If not, place it there.
Do you have rights to execute agents on the server?
First thing to do is to look in server's log.nsf.
Also, go to agent in designer, right click it and choose Agent Log. Also Test

Troubleshooting agents:
http://www-12.lotus.com/ldd/doc/domino_notes/7.0/help7_designer.nsf/f4b82fbb75e942a6852566ac0037f284/dbdc7357ef1ac9e18525704a003f5683?OpenDocument

Troubleshooting agents in Admin help:
http://www-12.lotus.com/ldd/doc/domino_notes/6.5/help65_admin.nsf/f4b82fbb75e942a6852566ac0037f284/cd64b0d113c2902f85256d9b004b2eb4?OpenDocument

Solve the problem, you remind me of your wife :)
0
 

Author Comment

by:Jaziar
ID: 22654277
Yes - the agent is created in a database that receives mail
Yes - the database is setting on a server
Maybe - When I do a test

'CN=Jaziar' has restricted rights to run LotusScript/Java agents on 'CN=MAIL01'.
Agent will be run by the Agent Manager after new mail messages are delivered.
Home mail server for 'CN=Jaziar' is 'CN=MAIL02'.
Agent will not run on 'CN=MAIL01' unless AMgr_DisableMailLookup ini variable is set to 1.

Started running agent 'Forwarding' on 10/06/2008 04:41:23 PM
Running on new mail messages: 1 total
Found 1 document(s) that match search criteria
Testing:  Ran LotusScript code
Done running agent 'Forwarding' on 10/06/2008 04:41:23 PM

Here is the problem.  I do not have access to the mail01 server.  I am a manager of the database I am using to get the mail but that is about all I can have access to.

why is it when I schedule the agent or run it from the menu it works great, it is only when new mail arrives seems to fail?  
0
 
LVL 22

Expert Comment

by:mbonaci
ID: 22658891
Hi Jaziar,
I think I know where the problem lies.

Check notes.ini setting AMgr_UntriggeredMailInterval.

It specifies a delay (in minutes) between running of the Agent Manager's check for untriggered mail.
Valid values are 1 minute to 1440 minutes (the number of minutes in a day).

Syntax:
AMgr_UntriggeredMailInterval=number of minutes

Default value is 60 minutes, which means that the Agent manager checks whether new e-mails have arrived once every 60 minutes and then acts on them by triggering your agent.
This may be the reason why you don't see the agent is triggered, cuz you expected it to run immediately after the e-mail came.

There are two things you can do:
1. Decrease this setting so it suites your requirements. Be aware of performance issues.
2. Leave the setting as it is and wait one hour (max) to see whether it will run.


Hope this will solve your problem,
Mb¤
0
 

Author Comment

by:Jaziar
ID: 22659245
Check notes.ini setting AMgr_UntriggeredMailInterval.

Is that the notes.ini on my client or is it on the server where the db is sitting?
0
 
LVL 22

Expert Comment

by:mbonaci
ID: 22659623
On the server.

You can do it manually, by opening the ini file (in server's Lotus\Domino\Data\ folder).

Or you can use Domino Administrator - Configuration - Server - Configurations - Add/Edit configuration.
Go to tab Notes.ini settings and click button "Set/modify parameters".

0
 

Author Comment

by:Jaziar
ID: 22659711
I am a developer - I/T will not let me change anything on the server side ( they are like that).  I guess I will have to be ok with the hour wait time.  Not sure my users will be though.
0
 
LVL 22

Expert Comment

by:mbonaci
ID: 22661436
So you waited and the agent is triggered eventually?

I don't get those admins of yours, I mean, they are here because of you, not the other way around.
So if you have the business requirement to respond to e-mail in, lets say, max 20 minutes, then they would normally have to oblige, wouldn't they?

Regards and good luck with them...

Mb¤
0
 

Author Comment

by:Jaziar
ID: 22661523
I think the agent is triggered once a day.  

They are also approx.  500 to 800 user mail files on the same server.  So my request means very little to them.  I may still need to look at the scheduled agent
0
 
LVL 22

Expert Comment

by:mbonaci
ID: 22661969
OK, whatever suites you best (but I don't understand what the number of users has to do with server's INI param modification - it has to be done once on each Domino mail server, not user's client).

If you want to go on with scheduled agent, replace this part of your code:

Do Until cur Is Nothing
       
        Call SendMemoFromTag( cur, "username", Chr(10) )
        Set cur = c.GetNextDocument( cur )
Loop


with this one:

Do Until cur Is Nothing
        If Not cur.HasItem( "flagProcessed" ) Then                'if it doesn't have flag - process it
                Call SendMemoFromTag( cur, "username", Chr(10) )
                Call cur.ReplaceItemValue( "flagProcessed", "1" )      'flag the processed e-mail
                Call cur.Save( True, False, True )                                'you must save the change in the doc
        End If
        Set cur = c.GetNextDocument( cur )
Loop


And make sure you select "All new and modified documents" as the agent's target (otherwise, you're going to go through all documents in a db every time the agent runs).
0
 

Author Comment

by:Jaziar
ID: 22662638
It does not like something above.  Even when I set it up as event driven, it does not send emails.  The agent runs but does not send a email
0
 
LVL 22

Accepted Solution

by:
mbonaci earned 500 total points
ID: 22663094
You did something wrong, I've just tested it and it works fine.

Does your code looks like this:
Sub Initialize
	Dim s As New NotesSession
	Dim db As NotesDatabase
	Dim c As NotesDocumentCollection
	Dim cur As NotesDocument
	
	Set db = s.CurrentDatabase
	Set c = db.UnprocessedDocuments
	
	Set cur = c.GetFirstDocument
	Do Until cur Is Nothing
		If Not cur.HasItem( "flagProcessed" ) Then                'if it doesn't have flag - process it
			Call SendMemoFromTag( cur, "username", Chr(10) )
			Call cur.ReplaceItemValue( "flagProcessed", "1" )      'flag the processed e-mail
			Call cur.Save( True, False, True )                                'you must save the change in the doc
		End If
		Set cur = c.GetNextDocument( cur )
	Loop
End Sub

Open in new window

0
 

Author Comment

by:Jaziar
ID: 22669564
Yep - it is working!!!

Thank you for staying with me until I got it running.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

I thought it will be a good idea to make a post as it will help in case someone else faces these issues. I trust this gives an idea how each entry in Notes.ini can mean a lot for the Domino Server to be functioning properly. This article discusses t…
This article covers general Notes 8.5 troubleshooting information including recreating the Notes\Data folder.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

809 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