Help - Agent - LotusScript to send mail from Server

Greetings!

I have the following scenario:

An application (located at the server) that runs an agent at a pre-determined time, in which it selects a certain condition and sends a mail message to a group of users.

The condition to generate the message is OK.

The recipient´s list is obtained from a hidden view and their names are being stored in an array with the instruction:

Dim RecNames (1 to 1000).

Here´s the first doubt: I wouldn’t like to use an array for this. I don´t know how many names I would get. It could be 100 or 1200. With the “Dim”, I had fixed this number in 1000.

What I really want is to populate a mail field with “n” names.

If I just simply add these names to a string variable, separated by commas or semicolons, there´s a problem when this string is interpreted in the mail form, specifically when the addresses have the @ sign. It gets all mixed up and the server generates an error message (“Could not send mail. Recipient not found.”)

Then there´s another problem: The application is not a “mail” application. The question is: Do I have to specifically inform the server to use a “mail form”? Or just by the fact that I mention in the agent “doc.BlindCopyTo = RecNames” it will produce a mail document?

Here´s the code:

Sub XYZPTLK

… all definitions and declarations…

… routine to generate the message contents… (in “MessageContents” variable)

… Now to the mail problem section…

… Here I already have the message contents and am preparing to capture the recipient´s name list.

Dim doc As NotesDocument

Set doc = New NotesDocument(db)

doc.Subject = "This is the message’s subject”

doc.Body = MessageContents

Xporte=“” ’ This variable was defined at the beggining

Set view = db.GetView( “RECIPNAMES” )

Set nav = view.CreateViewNav

Set entry = nav.GetFirst

Dim i As Integer

i = 1

Dim RecNames (1 To 1000)

While Not ( entry Is Nothing )

Xporte = entry.ColumnValues(0)

If Xporte<>“” Then

RecNames(i) = entry.ColumnValues(2)

Xporte = entry.ColumnValues(3)

End If

i = i+1

Set entry = nav.GetNext( entry )

Wend

doc.BlindCopyTo = RecNames

Call doc.Send(False)

End Sub

Any help would be very appreciated.

Thanks in advance and best regards,

Rubens

Subject: Help - Agent - LotusScript to send mail from Server

No need to use any arrays for this.
I would try using the notesItem.AppendToTextList method call something like

before loop:

sendDoc.BlindCopyTo=“”

Set itemBlindCopyTo = sendDoc.GetFirstItem(“BlindCopyTo”)

Within loop

Call itemBlindCopyTo.AppendToTextList(entry.ColumnValues(2))

Be wary though you can hit an upper limit of size of the BlindCopyTo field. You may need to send in batches out.

Subject: Help - Agent - LotusScript to send mail from Server

I’m still getting some errors I cannot find…

If I test the agent, it works fine, but when I leave it to the server to run, I get this message:

23/10/2007 03:00:22 AMgr: Agent (‘AnivHOJE-Envio’ in ‘rh001.nsf’) error message: No recipient list for Send operation

Just for testing purposes, I added a form named “Memo” to this database, with two fields: BlindCopyTo (names, multi-value) and Body (RichText). But still haven´t the chance to test it.

But I don´t believe this is necessary. For some reason the routine is not entering the recipient´s names in the BlindCopyTo field.

I also changed the sending routine to, instead of creating an array with “n” recipient´s names (it might overflow), I decided to send one message each time a valid address is found.

The first loop captures data to populate the Body field. This is working fine…

The second loop checks if is there any recipients to send the message… Here´s the problem…

The view “AnivHOJE-Envio” (used in the 2nd loop), has 4 columns:

  1. Real name of user

  2. Office location

  3. E-Mail address #1 (necessary)

  4. E-Mail address #2 (optional)

So, I check if column 1 is valid → entry.ColumnValues(0)

Then capture E-Mail Address 1 → entry.ColumnValues(2)

Send Mail

Check is is there any E-Mail Address 2 → entry.ColumnValues(2)

If valid, send another Mail

And so on…

Where did I go wrong?

Here´s the entire code…

Sub Initialize

Dim session As New NotesSession

Dim db As NotesDatabase

Set db = session.CurrentDatabase	



Dim view As NotesView

Set view = db.GetView( "AnivHOJE" )	

Dim nav As NotesViewNavigator

Set nav = view.CreateViewNav		



Dim entry As NotesViewEntry

Set entry = nav.GetFirst



Dim Xporte As String	

Xporte=""



Dim Aniversariantes As String	

Aniversariantes = ""	



Dim DataPlan As String

DataPlan = Right$(Str(Day(Date)+100),2)+"/"+Right$(Str(Month(Date)+100),2)+"/"+Right$(Str(Year(Date)+100000),4)

Aniversariantes = "Estes são os Aniversariantes do Poupatempo, para o dia "+DataPlan+":"

While Not ( entry Is Nothing )

	If entry.IsCategory Then

		Aniversariantes = Aniversariantes  + Chr$(13) + Chr$(13)+ "--- "+entry.ColumnValues(0)+" --------------------"

	Else

		Xporte = entry.ColumnValues(1)

		If Xporte="" Then

			Aniversariantes = Aniversariantes

		Else

			Aniversariantes = Aniversariantes + Chr$(13) + "     " + entry.ColumnValues(1) + " (" + entry.ColumnValues(2)+") " + entry.ColumnValues(3) + " - " + entry.ColumnValues(4)

		End If

	End If

	Set entry = nav.GetNext( entry )

Wend





Dim doc As NotesDocument

Set doc = New NotesDocument(db)

doc.Form = "Memo"

doc.Subject = "Poupatempo - Aniversariantes do dia "+DataPlan

doc.Body = Aniversariantes

Xporte=""	





Set view = db.GetView( "AnivHOJE-Envio" )

Set nav = view.CreateViewNav

Set entry = nav.GetFirst

Dim i As Integer

i = 1	



While Not ( entry Is Nothing )

	Xporte = entry.ColumnValues(0)

	If Xporte<>"" Then

		doc.BlindCopyTo = entry.ColumnValues(2)

		Call doc.Send( False)		

		Xporte = entry.ColumnValues(3)

		If Xporte<>"" Then

			i=i+1

			doc.BlindCopyTo = entry.ColumnValues(3)

			Call doc.Send( False)		

		End If

	End If

	i = i+1

	Set entry = nav.GetNext( entry )

Wend

End Sub

Thanks in advance,

Rubens

Subject: RE: Help - Agent - LotusScript to send mail from Server

Rubens,

You said:

======================================

So, I check if column 1 is valid → entry.ColumnValues(0)

Then capture E-Mail Address 1 → entry.ColumnValues(2)

Send Mail

Check is is there any E-Mail Address 2 → entry.ColumnValues(2)

If valid, send another Mail

======================================

However, it doesn’t look like you check the value of ColumnValues(2) here, before using it to Send. You do check ColumnValues(0)… - maybe columnValues(2) is your problem.

Xporte = entry.ColumnValues(0)

If Xporte<>“” Then

doc.BlindCopyTo = entry.ColumnValues(2)

Call doc.Send( False)

Xporte = entry.ColumnValues(3)

If Xporte<>“” Then

i=i+1

doc.BlindCopyTo = entry.ColumnValues(3)

Call doc.Send( False)

End If

Subject: RE: Help - Agent - LotusScript to send mail from Server

Hi Cesar.

In fact, if there´s any data in column 1, or Column.Values(0), there´s also data in column 3, or Column.Values(2). The view wuols not accept documents that doesn´t comply with this…

Testing this agent locally works fine - A-OK!

The problem is when it runs on the server.

I imagine that, when executing locally, my Notes Client “knows” what sending mail means, but the server doesn´t.

Note that I am not using arrays, or another type of grouping addresses. If is there an address, I just assign it to “doc.BlindCopyTo” and send it.

Question: In Notes R7, when you compose a Memo (from scratch), there´s no “BlindCopyTo” field, but the “SendTo” field already appears in the document (document proprierties - fields), even if it´s blank.

I will try changing the agento to use the SentTo field… Will post a comment later on.

Thanks for your interest.

Rubens

Subject: RE: Help - Agent - LotusScript to send mail from Server

I can’t see any reason why the server would not be able to send mail to a BlindCopyTo. It is a legitimate recipient field. I still recommend printing to the notes log the result of your ColumnValues(x) that you are using to send just to verify that it is not the data coming from the view.

Subject: GOT IT!!! - Help - Agent - LotusScript to send mail from Server

During composition, the Notes Client performs the operation of populating the Recipients field. But on the server it seems that this is not done (for I am not using a “real” Mail database). The problem was solved when I added another line instructing the population of the Recipients field…

doc.BlindCopyTo = entry.ColumnValues(2)

doc.Recipients = entry.ColumnValues(2) '<---------- That´s the one!

Call doc.Send(False)

Thank you all for the interest.

Regards,

Rubens

Subject: Ainda bem

Subject: Help - Agent - LotusScript to send mail from Server

Set the form to “Memo” to get it to be sent correctly.

You can also quickly get the names into the array from the view assuming that you can either use @DbColumn or @DbLookup to correctly retrieve the documents containing the recipient names.

Just use

varRecipients = Evaluate({@DbLookup(…)})

or

varRecipients = Evaluate({@DbColumn(…)})

and then the varRecipients will be a variant containing an array of names. No need to loop.

Subject: RE: Help - Agent - LotusScript to send mail from Server

Well, I have two columns with recipients names… Maybe I can combine them in one variable…

But what about the Server Mail?

When I test this agent using my local Notes Client, it somehow finds a way to use a “Memo” form from my environment. The database where it is operating from has no Memo form.

Whenever I program the agent to run in the Server, it seems the message cannot be creatd due to the lack of a Memo form…

Subject: RE: Help - Agent - LotusScript to send mail from Server

Did u say hidden view ? by role ? does the server have the role ? just checking :slight_smile:

Subject: RE: Help - Agent - LotusScript to send mail from Server

Actually is a view with “(name_of_the_view)” and “not exhibit in menu”, so no one could see itor use it… But it´s there for the server to use…

Subject: RE: Help - Agent - LotusScript to send mail from Server

Actually is a view with “(name_of_the_view)” and “not exhibit in menu”, so no one could see itor use it… But it´s there for the server to use…