Need help, my mailscript not work!

HiFirst, script is not my best side so i really don’t now if i do this the right way.

I run this script schedule every 5 minutes. I want to see if there are any new mail in my inbox. (MailInBox) If there are any new mail a want to set a value from my script so next time it jump over that mail. I also want to send e-mail to admin for each new mail it find.

I use this script and it send new mail entire time…

SCRIPT:

Sub Initialize

Dim session As New NotesSession



Dim db As NotesDatabase



Dim collection As NotesDocumentCollection



Dim doc As NotesDocument



Set db = session.CurrentDatabase



Set collection = db.UnprocessedDocuments



Set doc = collection.GetFirstDocument()



doc.AgentRun="1"



While Not(doc Is Nothing)



If(doc.AgentRun(0)="1") Then

'#########################

’ EMAIL - START

'#########################

	Dim SourceDoc As NotesDocument

	Dim Item As NotesItem

	Dim vValues As Variant

	Dim aValues As Variant

	Dim maildoc As NotesDocument

	Dim upperBound As Integer

	Dim MailNames(10) As String

	Dim buildsubject As String

	Dim vEvaluate As Variant

	Dim dbWebPath As String

'Set email distribution list

	Set db = session.CurrentDatabase

	Set maildoc = New NotesDocument( db )

	

	MailNames(0)="mail@url.com"

'Set the To, Subject and Body fields

	vEvaluate = Evaluate(|"/" + @replacesubstring(@subset(@dbname;-1);"\\";"/")+"/";|)

	dbWebPath = vEvaluate(0)

	viewName = "h_Toc/CE6A3D6B1F546C9405256708001671FF"

	theURL$ = "http://" & session.Internethostname & "." & session.Internetdomainname & dbWebPath & viewName & "/?OpenDocument"

	maildoc.Form="Memo" 

	maildoc.SendTo=MailNames

	sender="mail@url.com"

	maildoc.from=sender

	maildoc.SMTPOriginator=sender

	maildoc.Principal=sender

'Format the document

	buildsubject = "New Mail."

	maildoc.Subject = buildsubject

	maildoc.Body = "Mail from Project Inside " + Chr$(10) & Chr$(10) &  + "Follow URL:" & Chr$(10) & Chr$(10) & theURL$

	

	

	Call maildoc.Send(False)

'#############################

’ EMAIL - END

'#############################

	doc.AgentRun="1"

	Call doc.Save(True,True)

End If

	

	

	Call session.UpdateProcessedDoc(doc)

	

	Set doc = collection.GetNextDocument(doc)

	

Wend 

End Sub

Kind regards

Fredrik

Subject: Need help, my mailscript not work!

Fredrik,

your line:

If(doc.AgentRun(0)=“1”) Then

is where your problem is.

You should be testing for doc.AgentRun(0) <> “1”

hth

Tony

Subject: RE: Need help, my mailscript not work!

Thanx, i find it after a posted it. Sometimes you get blind when you work with it.