Manage Learn to apply best practices and optimize your operations.

Validating SendTo field for programmatically generated e-mails

This code will validate a person's name across all Domino servers within a domain, ensuring that mail is not sent to persons who don't exist.

This tip was submitted to the SearchDomino.com tip exchange by member Sunil Vishwakarma. Please let others know how useful it is via the rating scale at the end of the tip. Do you have a useful Notes/Domino tip or code to share? Submit it to our bimonthly tip contest and you could win a prize and a spot in our Hall of Fame.


View member feedback to this tip.

Most of the time our SendMail function sends e-mails to those individuals on the server who do not exist. So here I present a LotusScript function to validate e-mail recipients.

Public Function ValidateNames(varNames As Variant) As Variant
 On Error Goto errorHandler
 ValidateNames = ""
 
 Dim varTemp As Variant
 Dim varCommonNames As Variant
 
 Dim i As Integer
 Dim strAllNames As String
 
 If Isarray(varNames) Then
  varNames = Fulltrim(varNames)  
  If Ubound(varNames) >= 0 Then
   For i = Lbound(varNames) To Ubound(varNames)
    strAllNames = strAllNames & Cstr(varNames(i)) & ","
   Next
   
   varTemp = Evaluate(|@Unique(@Transform(
            @Explode("| & strAllNames & |";",");
            "x";
            @Name([ABBREVIATE];@Trim(@NameLookup([EXHAUSTIVE];x;"FullName"))
           )))|)
   ValidateNames = Fulltrim(varTemp)   
  End If
 Else
  varTemp = Evaluate(|@Trim(@NameLookup([EXHAUSTIVE];"| & Cstr(varNames) &|";"FullName"))|)
  varCommonNames = Evaluate(|@Name([ABBREVIATE];"| & Cstr(varTemp(0)) & |")|)
  
  If Isarray(varCommonNames) Then
   If varCommonNames(0) <> "" Then
    ValidateNames = varCommonNames(0)
   End If
  End If
 End If
 
 Exit Function
errorHandler:
 Msgbox "Error# " & Err & " - " & Error & " at line# "  & Erl
 ValidateNames = ""
End Function

What you need to do it call the function as follows:

mailDoc.sendTo = validateNams(mailDoc.sendTo)

or 

mailDoc.sendTo = validateNams(arrMailRecipients)

where arrMailRecipients (could be an array, avariant or a string) represents the individuals who should receive the e-mail.

And finally,

If mailDoc.sendTo(0) <> "" then
    Call mailDoc.send(false)
End If


MEMBER FEEDBACK TO THIS TIP

What happen with Internet addresses? This is OK for Lotus users but not for this e-mail address type. I would change the function and the "wrong adresses" that they contains something like "@doman.something". I would also mark like "OK" not wrong.

But I think the best form to work would be:

On error Goto ErrorMail 
Call doc.send(.....) 

exit sub 

ErrorMail: 
print error 
resume next 

If you send a recipients' list it works for everyone except the wrong ones. The new R5 and R6 releases work fine with this at least.

—Pedro F.


Do you have comments on this tip? Let us know.

Dig Deeper on Lotus Notes Domino Administration Tools

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchWindowsServer

Search400

  • iSeries tutorials

    Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...

SearchDataCenter

SearchContentManagement

Close