Accessing Mail Fields on When New Mail Has Arrived Agent

I have an agent running on After New Mail Arrives, the basic idea is to take the name of the sender, which is provided by a calculated field ‘MaxFrom’ which is based on a formula similar to that in the ‘Who’ column in the Inbox. Once I have this name I will carry out searches on another database to find related information, e.g. Telephone Number.

I am stuck at the first hurdle though. The MaxFrom field does show the correct data when I open the email, however, I do not appear to be able to access that data by the agent when mail arrives.

As a test I have written the script to change the MaxPhoneScript field to the MaxFrom value (this will eventually display a searched telephone number). The agent does run, but instead of changing the MaxPhoneScript field from its default value “Test” it removes the data, suggesting I am not accessing the value.

When a mail is generated internally within the Notes domain, there is no problem as my MaxFrom field displays the sender before the email is sent. In other words the problem occurs with inbound mail arriving from The Internet, I assume therefore the MaxFrom field value does not exist until I open the document or something of that order. I have tried Editable, Computed When Composed and Computed Fields.

I assume there is something wrong with my script, but have spent many, many hours trying to resolve the problem, so any help would be appreciated.

Thanks Mark

Sub Initialize

Dim session As New NotesSession

Dim db As NotesDatabase

Dim collection As NotesDocumentCollection

Dim doc As NotesDocument    

Dim MaxName As Variant



Set db = session.CurrentDatabase

Set collection = db.UnprocessedDocuments

Set doc = collection.GetFirstDocument()



While Not(doc Is Nothing)

If doc.Form(0)="Memo" Then

MaxName =doc.GetItemValue("MaxFrom")

doc.MaxPhoneScript = MaxName(0)

Call doc.Save( True, True )

End If

Call session.UpdateProcessedDoc( doc )

Set doc = collection.GetNextDocument(doc)

Wend

End Sub

Subject: Accessing Mail Fields on When New Mail Has Arrived Agent

Is ‘MaxFrom’ a field you have created on the Memo form? If so, it won’t exist on your email document until you open the document in the UI with the form - the router only puts the standard fields in the document record, regardless of what’s on the Memo form. You need to get your script calculate the value for MaxFrom directly.

If you have a long formula and don’t want to re-write it, try using the Evaluate() function to run the formula macro from within your script.

HTH

Michelle

Subject: RE: Accessing Mail Fields on When New Mail Has Arrived Agent

Makes sense and explains where I am going wrong, struggling with the Evaluate() function though.

The MaxFrom field is a field I have created on the form. Could you confirm that using Lotus Script, I should be able to manipulate the standard From field, convert the mail address from the form “Mark Maden” m.maden@networkconnect.co.uk to the form Mark Maden. Then search using that name in another database for a telephone number associated with that name and then insert the number in another field on the form ready for display in the Inbox and the email Memo form.

Many thanks.

Subject: Accessing Mail Fields on When New Mail Has Arrived Agent

Try the following code to set context on the newly arrived document.

I used the code in a Spam Mail template to check a users’ incoming mail before it hit the inbox

Dim session As New NotesSession

Set db = session.CurrentDatabase

session.ConvertMIME = False

Set doc = session.DocumentContext

Hope that helps.