Agent for autoforwarding mails in lotus notes

There's a requirement of autoforwarding of mails from one notes mailing database to some external mail address when a new mails comes in mailing database.

I have created an agent for this which is forwarding new mails.

Dim db As NotesDatabase
Dim Maildoc As NotesDocument
Set db=session.currentDatabase
Dim doccoll As NotesDocumentCollection
Set doccoll=db.unprocessedDocuments
Dim forwardDoc As NotesDocument
Dim a As Integer
Print "agent started runing"
Print "agent runnning for " doccoll.count " documents"
    For a=1 To doccoll.count
        Set forwardDoc=doccoll.GetNthDocument(a)
        Set Maildoc = New NotesDocument( db )
      Call forwardDoc.CopyAllItems( Maildoc, True )
      Maildoc.Principal = forwardDoc.From(0)
      Maildoc.SendTo =""
      'Call maildoc.Save(True,True)
      Call Maildoc.Send(True)
      Print a

Exit subs

Agent is trigered on event "when a new mail has arrived"

But agent is only running for one time .
means intaily when database has no mails i have pasted some documents in it.
it works for one time .
After this again i have pasted some document .So the agent should run but its not working?
Who is Participating?
wuesten_fuchsConnect With a Mentor Commented:
I guess that simply new _real_ mails came in (delivered by the router) and triggered the agent.
As I wrote above, the agent could not have been triggered since he had set "new mail" as the trigger but tried to test with _pasting_ mail documents into it.
on the server console you can type "tell amgr sched" and see if agent is registered in agent manager with the appropriate action.
V M  [agent name] [Path to agent]

Also is the agent should provide log of when agent last run against x number of documents.
I believe if the agent is set to after new mail  then it is kicked off by the router process, so after initial run copying documents into the database will not trigger it, it should be mailed to the database so that router tasks detects it.
Possibly somone can confirm/refute that.

Alternative is to use event when documents ceated or modified and create a flag field in documents that are forwarded.
Sjef BosmanGroupware ConsultantCommented:
Is mail received directly into this mail database, or in a replica?

Check the server's log .nsf database, Miscellaneous section, where the agent might have left you an error message.
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

If you would like to have a copy of the mail delivered to the mail file as well in addition to having it forwarded, than the best solution is to simply create a mail file rule for "Send copy to" - you probably need an 8 + mail template to have this rule available.

If you would like to forward the mails without having a copy in the mail file, than use the forwarding email address field in the person document / mail-in document.

The agent is not a recommended solution.
Pasting mail documents into a database does NOT trigger "after new mail has arrived" agents. Such agents are ONLY triggered when the router task _delivers_ mail to the database.

If you want your agent to be triggered when you paste mail documents into the database, then you need to specify its trigger as "after documents are created or modified" (but be aware of the few minutes of delay until your agent runs after you pasted documents).
GlactusAuthor Commented:
The agent started working, I dont know I diid nothing but it started working automatically.
Sjef BosmanGroupware ConsultantCommented:
Brilliant! Does nothing and it works! There must be many companies that are desperately looking for a magician like you as Administrator...  ;-))
Sjef BosmanGroupware ConsultantCommented:
Very plausible explanation.
GlactusAuthor Commented:
I've requested that this question be closed as follows:

Accepted answer: 0 points for Glactus's comment http:/Q_26964453.html#35963892

for the following reason:

The agent started working, I dont know I diid nothing but it started working automatically.
See my explanation in Comment ID 35964620.
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.