Example 3: Checking an email address

Previous Next

This example shows how an external component checks if an email address string entered or changed by the user is known to a mail server.

This is an example of an invocative constraint implementing a restrictive business rule. The rule is that email addresses that do not exist in the address book of MS Exchange cannot be entered.

If this example is implemented in conjunction with example 2 (resolving the email address), then the constraint in example 2 will be evaluated before the constraint in example 3 since corrective constraints are evaluated before restrictive constraints. Normally if example 2 resolves the address successfully, then example 3 will not raise a violation. This is desired behavior.

The example uses the Travel Agency case (Expanded Version).

Component

Component Name

USMAIL

Component Prog ID

UsMail.Class1

Method Name

CHECK_ADDRESS_EXE

Physical Method Name

checkAddress

Parameters of RESOLVE_ADDRESS

In - String

Return - Long Integer

 

Query protocol assocation

Component Name

USMAIL

Protocol Name

CHECK_ADDRESS

Exe Method Name

CHECK_ADDRESS_EXE

 

Constraint

Constraint Name

CHECK_EMAIL

Message

Email address is not correct.

Transition Table

(null)

Fire on Insert

(null)

Fire on Delete

(null)

Fire on Update

(null)

 

Set the SQL statement to:

INVOKE    usmail.check_address WITH
SELECT    email
FROM      person
WHERE     email is not null

 

Code of invoked subprogram

The component establishes a connection to a Microsoft Exchange server using Microsoft's standard MAPI component. The exchange server returns a value indicating whether the address exists or not. The invoked component then returns 1 if the address is unknown (constraint violation), 0 if the address is correct, and -1 if an error occurs.

Visual Basic code of subprogram directly invoked by USoft:

Const USOFT_STATUS_VIOLATION = 1
Const USOFT_STATUS_NO_VIOLATION = 0
Const USOFT_STATUS_ERROR = -1
Public Function checkAddress(address As String, _
                                    Optional profile_name As String, _
                                    Optional password As String) _
                                    As Long
   Dim objSession As Object
   Dim objMessage As Object
   On Error GoTo on_error
   ' Initialize this function to return a violation
   checkAddress = USOFT_STATUS_VIOLATION
    If Len(address) = 0 Then
      checkAddress = USOFT_STATUS_NO_VIOLATION
      Exit Function
   End If
   Set objSession = newSession(profile_name:=profile_name, _
                                 password:=password, _
                                 no_mail:=True)
   ' Create a new message and check how the address will be resolved
   Set objMessage = newMessage(objSession, address)
   If Not resolveMsgAddress(objMessage) = USOFT_UNRESOLVED_ADDRESS Then
      ' Return absence of violation
      checkAddress = USOFT_STATUS_NO_VIOLATION
   End If
   cleanUp objSession, objMessage
   Exit Function
on_error:
   If Not ignoreError() Then
      showError "checkAddress"
      checkAddress = USOFT_STATUS_ERROR
   End If
   cleanUp objSession, objMessage
End Function

 

See also

Using RDMI

Rules-Driven Method Invocation (RDMI)