We help IT Professionals succeed at work.

Lotus Notes Agent "Before mail arrives agent" works when email comes from outside Notes system but not inside.

mackmcrae
mackmcrae asked
on
I have written a simple before mail arrives agent to look for a phrase in the email body and then change the subject.  Works perfectly if I go out to gmail and send an email into my email box.  But if I go to another Notes box and send an email to myself, it doesn't work.  

I have written dozens of these before and they have always worked, so I know the rules (only one per database, must be signed by someone who has rights to run agent on router/server).  

I know the agent has rights, etc. because it runs perfect when I email from gmail or some other outside email system.  But it doesn't work if the email comes from someone using Notes with a domain connection.  I know this because I sent an email to the mailbox from a client's system (using VNC) logged in as a client's user in their system (which is cross-certified with mine)..

Never seen this before.  Any ideas?
Comment
Watch Question

Commented:
Check all settings explained here:
http://www.experts-exchange.com/Q_25137729.html
In your agent, are you processing the body as MIME or RichText?  If you're only handling MIME, that may be your problem.

Other than that, I really can't say without seeing the code.

One thing you can try, though, is to change the agent trigger to "after new mail arrives". That way, you can run the debugger to see what it really going on.

Author

Commented:
The setting explained in that link concern agents fired off by the agent manager.  I'll check these, but the agent manager doesn't control "before mail arrives" agents.  The mail router does.  This is a very special type of agent.  And I know it works because it works every time I send email from an outside address and it never works if I send from an inside address.

Author

Commented:
Bill-Hanson:

Now that's an interesting idea.  Rich text inside, mime outside.  Maybe the agent doesn't see the text correctly in the rtf.

The code is quite simple.  

@If(@Contains(Body; "You have received a new fax");FIELD Subject:="You have received a new fax "+Subject;"");
SELECT @All

I'll change to after new mail arrives and see what happens.  I think I tried that and got the same results.  If so, that does seem to narrow it down to some type of different email body format.
Changing the trigger type will not change the results, it would only allow you to debug the code easier.

Using @Formula, you should not have to worry about whether it is MIME or RichText.

Another thing you can try to troubleshoot this is to create a button on the form that displays "Yes" or "No" using the same test as your agent code (see below). If the result does not make sense, then copy the "You have received a new fax" text directly from the body of the email and paste it into a text editor that can display the text as HEX.  You may find a strange character.  Compare the HEX in the email with the HEX in your @Formula.  It's a long shot, but I can't think of anything else at the moment.

@Prompt([OK]; @If(@Contains(Body; "You have received a new fax"); "Yes"; "No"); "");

Author

Commented:
Bill:

That was a good test.  The same thing happened with the after the email arrived agent.  That means it's not the agent running on the router.  The agent says it ran on 2 documents, but it only modified one.  Let me try the button and the hex editor.

Author

Commented:
I tried the code for the button you suggested.  Interesting: I get a yes on the outside mail.  I get nothing on the inside mail.  The code runs, but no yes or no info box pops up.  Strange.
To debug, you can use the print statement which will print msgs to the server console and the notes log.
Strange indeed.  I rarely use @Formula in agents even when they are simple like this one.  You could try porting it over to LotusScript so that it can be debugged.

Here's what the code should look like...

Note that this is setup to run on "before new mail arrives".  If you want to change it to "after new mail arrives", you'll need to change a few things.
Sub Initialize()
	Dim session As New NotesSession
	Dim memo As NotesDocument
	Dim body As String
	session.Convertmime = true
	Set memo = session.Documentcontext
	body = memo.Getfirstitem("Body").Text
	If (InStr(1, body, "You have received a new fax", 5) > 0) Then
		memo.Replaceitemvalue "Subject", "You have received a new fax " + memo.Getitemvalue("Subject")(0)
		memo.Save True, False
	End If
End Sub

Open in new window

And here's the verison that can be used in "after new mail arrives"

Sub Initialize()
      Dim session As New NotesSession
      Dim db As NotesDatabase
      Dim dc As NotesDocumentCollection
      Dim memo As NotesDocument
      Dim body As String
      session.Convertmime = True
      Set db = session.Currentdatabase
      Set dc = db.Unprocesseddocuments
      Set memo = dc.Getfirstdocument()
      Do Until (memo Is Nothing)
      body = memo.Getfirstitem("Body").Text
            If (InStr(1, body, "You have received a new fax", 5) > 0) Then
                  memo.Replaceitemvalue "Subject", "You have received a new fax " + memo.Getitemvalue("Subject")(0)
                  memo.Save True, False
            End If            
            Set memo = dc.Getnextdocument(memo)
      Loop
End Sub

Author

Commented:
Well that seems to work.  Something odd between lotuscript and formula.  Thank you, Bill.  I'd give you 5,000 points if I could.  Let me test in production, and then I'll be back to close.

Author

Commented:
It's working in production on several mailboxes.  Thanks.

Author

Commented:
Thanks.
Happy to help