Creating a Agent

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

JaziarAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
mbonaciConnect With a Mentor Commented:
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
 
mbonaciCommented:
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
 
JaziarAuthor Commented:
I can't get the agent to save to test it.  I am not sure how to set up the agent.
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
mbonaciCommented:
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
 
mbonaciCommented:
I can read your mind :)
0
 
JaziarAuthor Commented:
I wish you could teach that trick to my wife :)
0
 
mbonaciCommented:
I presume it works (since you're comparing it with your wife)?

Or you want to say that it doesn't work :)
0
 
JaziarAuthor Commented:
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
 
JaziarAuthor Commented:
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
 
mbonaciCommented:
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
 
JaziarAuthor Commented:
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
 
mbonaciCommented:
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
 
JaziarAuthor Commented:
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
 
mbonaciCommented:
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
 
JaziarAuthor Commented:
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
 
mbonaciCommented:
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
 
JaziarAuthor Commented:
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
 
mbonaciCommented:
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
 
JaziarAuthor Commented:
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
 
JaziarAuthor Commented:
Yep - it is working!!!

Thank you for staying with me until I got it running.
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.