Agent sends mail to blank SendTo. Ambiguous Names causing this?

I have a LotusScript agent kicked off when someone clicks a button. It sends mail to recipients, and the name(s) are gotten from a field in the document.

Oftentimes email is sent to no one (the SendTo field is blank). I’m pretty sure this is caused when Lotus Notes sees the name in two places, such as the company directory and the user’s personal address book. The agent does not throw up any type of error or prompt box.

My lame suggestion to those users is for them to remove the person from their personal address book, but that’s not really a good solution.

I’m wondering if something changed between Notes 6.5 and 8.5. I do not recall having this problem before our recent upgrade.

Thanks for any suggestions.

Subject: post your code

Subject: oh, man … :slight_smile:

OK. Sorry this is so big and messy.

It starts with formula, then calls a LS agent.

Formula code:

REM {If in read mode, attempt to change to edit mode.};

@If(@IsDocBeingEdited;@Success;@Command([EditDocument]));

@If(!@IsValid; @Do(

@SetField(“StatusRefresh”; “”);

@Return(“”)); @Success);

REM {Attempt to save. If successful, continue.};

@If(!@Command([FileSave]); @Do(

@SetField(“StatusRefresh”; “”);

@Return(“”)); @Success);

@If(@Prompt([YesNo]; “Continue?”; “This will change the status of this request to Cancelled/Withdrawn. No more work will be done on this change request. Please click Yes to confiirm.”);“”;@Return(“”));

@SetField(“CancellationReason”;@Prompt([OkCancelEdit]; “Cancel/Withdraw Reason”; “Please type your reason below.”; “”));

@SetField(“Status”;“Cancelled/Withdrawn”);

@SetField(“EmailSubjectLine”;"CR " + CRNumber + " - " + BriefChangeDesc + “: Cancelled/Withdrawn”);

@SetField(“AssignedTo”;“”);

@SetField(“NextStep”;“None. This request will not move forward from this point.”);

@SetField(“SendToGroup”; ITDirector:Requestor);

@SetField(“ccGroup”;USBLApprover:CMApprover);

@SetField(“StatusRefresh”; “”);

@SetField(“NextDocAuthors”; “”);

@SetField(“CancelledDate”;@Now);

@SetField(“PastComments”;PastComments : LastComment);

@SetField(“LastComment”;@Text(@Now;“D0T1Z2S2”) + " - " + @Name([CN];@UserName) + " has marked this request as Cancelled/Withdrawn.");

@SetField(“MsgPromptTitle”;“Cancelled/Withdrawn”);

@SetField(“MsgPrompt”;“This request has been marked as Cancelled/Withdrawn.”);

@Command([FileSave]);

FIELD SaveOptions := “0”;

@Command([ToolsRunMacro]; “(CancelCR)”)

Lotuscript agent:

Sub Initialize

'CLIENT: 	Notes

'PURPOSE: Notify Project Participants that a CR has been cancelled

'This agent is called from an action button, whch has already checked for required fields and updated several fields.

'This agent sends the notification message.	

Dim session As New NotesSession

Dim db As NotesDatabase

'Dim doc As NotesDocument	

Dim maildoc As NotesDocument	

Dim rtItem As NotesRichTextItem

On Error Goto ErrorHandler		



Dim uiw As New notesuiworkspace

Dim uidoc As notesuidocument

Set uidoc = uiw.currentdocument



Set db = session.CurrentDatabase	

Set doc = uidoc.document



Call uidoc.save 

Call uidoc.close



Call doc.RemoveItem( "SaveOptions" )



'Update document security	

doc.DocAuthorsVariable = doc.NextDocAuthors



Call doc.Save(False,False)



'Create and send email notification message	

Set maildoc = New NotesDocument(db)

maildoc.Form = "Memo"



maildoc.Subject = "CR " & doc.CRNumber(0) & " Cancelled/Withdrawn"

'maildoc.~_ViewIcon = 117



Set rtitem = New NotesRichTextItem(maildoc,"body")	



Call RTItem.AppendStyle(PlainDkBlueText) 

Call rtitem.appendtext("A Change request has been marked as Cancelled/Withdrawn.")



Call rtitem.appendtext("This change has been cancelled/withdrawn.")



Call rtitem.addnewline(2)

Call rtitem.appendtext("Change Type:" & Chr(9) & Chr(9))		

Call RTItem.AppendStyle(BoldText) 	

Call rtitem.appendtext(doc.CRType(0))



Call rtitem.addnewline(1)

Call RTItem.AppendStyle(PlainDkBlueText) 

Call rtitem.appendtext("CR #:" & Chr(9) & Chr(9) & Chr(9))		

Call RTItem.AppendStyle(BoldText) 	

Call rtitem.appendtext(doc.CRNumber(0))



Call rtitem.addnewline(1)

Call RTItem.AppendStyle(PlainDkBlueText) 

If doc.CRType(0) = "Break/Fix" Then

	Call rtitem.appendtext("HEAT Ticket #:" & Chr(9) & Chr(9))		

	Call RTItem.AppendStyle(BoldText) 	

	Call rtitem.appendtext(doc.HeatTicket(0))

Else		

	Call rtitem.appendtext("IT Project #:" & Chr(9) & Chr(9))		

	Call RTItem.AppendStyle(BoldText) 	

	Call rtitem.appendtext(doc.ProjectNumber(0))		

End If



Call rtitem.addnewline(1)

Call RTItem.AppendStyle(PlainDkBlueText) 

Call rtitem.appendtext("Brief Description:" & Chr(9))		

Call RTItem.AppendStyle(BoldText) 	

Call rtitem.appendtext(doc.BriefChangeDesc(0))	



Call rtitem.addnewline(1)

Call RTItem.AppendStyle(PlainDkBlueText) 

Call rtitem.appendtext("Implementation Date:" & Chr(9))		

Call RTItem.AppendStyle(BoldText) 	

Call rtitem.appendtext(doc.ImplementDate(0))	



Call rtitem.addnewline(2)

Call RTItem.AppendStyle(PlainDkBlueText) 

Call rtitem.appendtext("Requestor:" & Chr(9) & Chr(9))		

Call RTItem.AppendStyle(BoldText) 	

Call rtitem.appendtext(doc.RequestorCN(0))



Call rtitem.addnewline(2)

Call RTItem.AppendStyle(PlainRedText) 	

Call rtitem.appendtext("Cancellation Reason:")

Call rtitem.addnewline(1)

Call RTItem.AppendStyle(BoldRedText) 	

Call rtitem.appendtext(doc.CancellationReason(0))



Call rtitem.addnewline(2)

Call RTItem.AppendStyle(PlainDkBlueText) 

Call rtitem.appendtext("Action Required:"& Chr(9))		

Call rtitem.appendtext(doc.NextStep(0))



Call RTItem.AppendStyle(SmallBlueText) 

Call rtitem.addnewline(2)

Call rtitem.appendtext("Link to the Change Request document --> ")

Call rtitem.appenddoclink(doc,"")	



'Populate SendTo field with multivalues:

vST = doc.GetItemValue("SendToGroup")	



Forall st In vST		

	iArrayCount = iArrayCount + 1

	Redim Preserve XSendTo(iArrayCount)

	XSendTo(iArrayCount-1) = st

End Forall	

maildoc.sendto = XSendTo()



'Populate CopyTo field with multivalues:

vCT = doc.GetItemValue("ccGroup")	



Forall ct In vCT		

	iArrayCount = iArrayCount + 1

	Redim Preserve XCopyTo(iArrayCount)

	XCopyTo(iArrayCount-1) = ct

End Forall	

maildoc.copyto = XCopyTo()



'Blind copy Russ during system testing

maildoc.blindcopyto = "Russ McBride"



maildoc.From = session.username

maildoc.Principal = session.username



On Error 4294 Goto AddressDeliveryError   'Error 4292 - Unable to send mail, no match found in Name & Address Book(s) 

On Error 4000 Goto AddressDeliveryError   'Error 4000 - Unable to send mail, no match found in Name & Address Book(s) 

Call maildoc.send (False)		



Msgbox doc.MsgPrompt(0),0,doc.MsgPromptTitle(0)



'Call uidoc.save 

'Call uidoc.close



Exit Sub

AddressDeliveryError:

If Err = 4294 Or Err = 4000 Then  'Unable to send mail, no match found in Name & Address Book(s) 

	Err = 0 'Clear the Error for additional processing

	Set maildoc = New NotesDocument(db)

	maildoc.Form = "Memo"

	maildoc.Subject = "Address Delivery Error: SDLC, ProjectApproved"

	maildoc.SendTo = "Russ McBride"

	Set rtItem=New NotesRichTextItem(maildoc,"body")

	Call rtItem.AppendText( "Unable to send mail, no match found in Name & Address Book(s).  See Project " & doc.ProjectNumandName(0))

	maildoc.Send False

End If



Print "[/" & db.FilePath & "/Thank+You+Redirect+Form?OpenForm&AddressDeliveryError&" & doc.UniversalID & "]"



Exit Sub

ErrorHandler:

Print "<br> Error#:" & Str(Err) & "<br>" & "Error Description:" & Error$ & "<br>" & "Line#: " & Cstr(Erl) & "<br><br>" & sDebugBuffer

Resume Next

End Sub

Subject: mail sent to no one

doesn’t really make sense because you should be getting a “no names found to send mail to” error. Also, if you are pulling your SendTo list from a field on the document couldn’t you just do a check on that field and if it’s blank then cancel the action?

Subject: I agree. Doesn’t make sense to me either.

The problem is not that the document’s field is empty. It definitely has a value.

I’m 99 percent sure the problem is that the user clicking the button has an entry in their personal NAB. My strong hunch is, when Notes tries to deliver (or maybe just address the message), it sees an entry for “John Smith” in both the company Domino Directory and the user’s personal NAB. I’m not sure what should happen, but I think Notes is not handling it gracefully (sending the message with a blank SendTo field).

This code is something I’ve used in Notes workflow applications for years (at least since R5). I started to notice the difference around Notes 8.0 or 8.5.

I BCC myself on many of the messages, so I can see the message, who sent it, follow the doclink to the document to confirm it has a name in the SendToGroup field, etc.

I’ve convinced myself that something changed around Notes 8.0, but I’m not sure how best to change my code (ugh. It’s all over the place. Hope I don’t have to).

Thanks for any suggestions or thoughts.

Subject: ambiguous names

if notes does find a duplicate, i.e. public and private address book entries, the user would/should be presented with the ambiguous names dialog box asking them to select the correct address. If you are sending it in the back end then an error would be generated “unable to send mail, multiple matches found in the domino directory”. You could see this error in either the agent log or in the server log if it’s send via a scheduled agent. To avoid this from happening you can append your Domino domain name to the end of the address(es). For example, add @ACME to the end of “John Smith/APAC” to produce “John Smith/APAC@ACME”. If there are 2 matches for this user it won’t matter. The mailer will skip the validation and will let the router resolve the address. If the server’s router finds 2 or more matches it will produce a delivery failure back to the sender. But in your scenario, where you think it’s a conflict between the public and personal address books, the e-mail will get sent as it will resolve to the address from the public address book(s).

Subject: Great suggestion, Paul. Thank you!

Great suggestion, Paul. Thank you!