Forum Friday

Today’s Forum Friday posting is in response to this question about sending mail from a Lotusscript agent by H Falzone. 

He (she?) is having problems sending a mail to multiple users from an agent.

Here is the existing code:

Sub Initialize
Dim session As New Notessession
Dim db As Notesdatabase
Dim view As NotesView
Dim doc As NotesDocument
Dim maildoc As NotesDocument
Dim rtitem As NotesRichTextItem

Set db = session.CurrentDatabase
Set view = db.GetView( "TESTER" )

Set Col = session.CurrentDatabase.UnprocessedDocuments
For x = 1 To Col.count
Set doc = col.getnthdocument(x)

Set maildoc = New NotesDocument( db )
Set rtitem = New NotesRichTextItem( mailDoc, "Body" )
Call rtitem.AddNewLine( 2 )
Call rtitem.AppendText( "You are responsible for a lease that expires in 30 days. Please contact Legal Services ( Gidget DiRienz and Responsible Attorney ) to indicate your intentions regarding this lease." )
Call rtitem.AddNewLine( 2 )
Call rtitem.AppendText( "You will also need to update FMV for this property." )
Call rtitem.AddNewLine( 2 )
Call rtitem.AppendDocLink( doc, db.Title )

Dim recipients( 1 To 3 ) As String
recipients( 1 ) = doc.contactname(0)
recipients( 2 ) = doc.RespAttorney(0)
recipients( 3 ) = doc.NoticesSentTo(0)

maildoc.Form = "Memo"
maildoc.principal="MHP Legal Department"
maildoc.From = maildoc.Principal(0)'<—- !!
maildoc.ReplyTo = "Gidget DiRienz and Responsible Attorney"
maildoc.CopyTo = doc.EnteredBy
maildoc.Subject = "* * * LEASE UP FOR RENEWAL IN 30 DAYS * * * " + doc.ViewDisplay(0) +" – "+ doc.Status(0)
maildoc.~_ViewIcon = 94
Call maildoc.send (False,recipients)

Next
Exit Sub

End Sub 

maildoc.Send is called with the argument recipients, which is declared as an array. That should work, but I would use a zero based array, perhaps that is what’s wrong.

Run the code through the debugger and make sure there really are values for all the array elements, and see what the array looks like.

But why not simply drop that argument to .Send() and store the values in the field SendTo in the document?

Simply assign the array to the field like this: maildoc.SendTo = recipients

That is IMHO the best way to make sure you get everything right.

 

I also spot another big no-no… Using GetNthDocuments(). This is VERY slow as soon as you have more than just a few entries in the document collection. Use GetFirstDocument() and GetNextDocument() instead.

Here is my version of the same code. Not tested, but something to start with. My additions are in red.:

Sub Initialize
Dim session As New Notessession
Dim db As Notesdatabase
Dim view As NotesView
Dim doc As NotesDocument
Dim maildoc As NotesDocument
Dim rtitem As NotesRichTextItem
Dim recipients(2) As String

Set db = session.CurrentDatabase
Set view = db.GetView( "TESTER" )

Set Col = session.CurrentDatabase.UnprocessedDocuments

Set doc = col.GetFirstDocument()

Do while Not doc is Nothing

Set maildoc = New NotesDocument( db )
Set rtitem = New NotesRichTextItem( mailDoc, "Body" )
Call rtitem.AddNewLine( 2 )
Call rtitem.AppendText( "You are responsible for a lease that expires in 30 days. Please contact Legal Services ( Gidget DiRienz and Responsible Attorney ) to indicate your intentions regarding this lease." )
Call rtitem.AddNewLine( 2 )
Call rtitem.AppendText( "You will also need to update FMV for this property." )
Call rtitem.AddNewLine( 2 )
Call rtitem.AppendDocLink( doc, db.Title )

recipients(0) = doc.contactname(0)
recipients(1) = doc.RespAttorney(0)
recipients(2) = doc.NoticesSentTo(0)

maildoc.Form = "Memo"
maildoc.principal="MHP Legal Department"

maildoc.SendTo = FullTrim(recipients)
maildoc.ReplyTo = "Gidget DiRienz and Responsible Attorney"
maildoc.CopyTo = doc.EnteredBy
maildoc.Subject = "* * * LEASE UP FOR RENEWAL IN 30 DAYS * * * " + doc.ViewDisplay(0) + " – " + doc.Status(0)
maildoc.~_ViewIcon = 94
Call maildoc.send (False)
Set doc = col.GetNextDocument(doc)
Loop

End Sub
 

I will assume that EnteredBy on the processed document is a multi value field, otherwise I would use doc.EnteredBy(0) instead.

If you want multiple addresses in the CopyTo field, just use the same technique as for the SendTo field.

Also, assigning maildoc.From a value will not work, the mail router will automatically put the name of the agent signer in there. Use the Principal field like you do, and sign the agent with a generic ID you create for mailings.

 

Leave a Reply