In lotusscript I’m sending automated emails. I’d like to be able to detect the above error (when the user I’m sending an email to doesn’t exist, or is blank etc.) without just resorting to error handling.
How can I check I’ve got a valid “To” field before sending the memo?
Take each address and use it to do a lookup in the $Users view of all your Domino Directories. In Domino 8 or above, use the NotesDirectory class. In earlier versions, you will have to use the NotesDatabase class for each directory. If you get a hit, you have a valid address. If you don’t get a hit, you may still have a valid address. You can use the Evaluate function to execute @ValidateInternetAddress with the [Address821] argument to determine if it looks like a valid internet address. If it is, you can just assume it is valid, or you can do further testing.
For further testing, if the address list might actually contain RFC822 formatted addresses (e.g., “joe user” <joe@acme.com>), then use you should use the Evaluate function to execute @Name([Address821] in order to strip it down to the RFC821 (joe@acme.com) format. Then check the the domain portion (after the @) matches one of the valid SMTP domains that your server is configured to accept. If it is not one of your domains, than you have done as much as you can do, so assume it is valid and cross your fingers. If it is one of your domains, parse out the portion that comes before the ‘@’ and do another lookup into $Users.
Note that depending on your server’s settings for address resolution, some of this may not be necessary.