Component Example 2: Resolving an email address

  • 7 January 2021
  • 0 replies
  • 16 views

Badge +1

This example shows how an email address string entered or changed by the user is automatically turned into an existing email address when possible.

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

Component Name USMAIL
Component Prog ID UsMail.Class1
Method Name RESOLVE_ADDRESS
Physical Method Name resolveAddress
Parameters of RESOLVE_ADDRESS In - StringReturn - String

In the data model, to the PERSON table, add an EMAIL column based on a regular CHAR(60) domain (On Oracle7: VARCHAR2).

Add a constraint:

Constraint Name RESOLVE_EMAIL
Message (no message)
Transition Table (null)
Fire on Insert (null)
Fire on Delete (null)
Fire on Update (null)

Set the SQL statement to:

UPDATE person
SET    email =
(
   INVOKE usmail.resolve_address WITH
   SELECT email
)
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 the email address if it can be found. If not, the original input string is returned.

Visual Basic code of subprogram directly invoked by USoft:

Public Function resolveAddress(address As String, _
Optional profile_name As String, _
Optional password As String) _
As String

Dim original_address As String
Dim objMessage As Object
Dim objSession As Object
On Error GoTo on_error
original_address = address
resolveAddress = address
Set objSession = newSession(profile_name:=profile_name, _
password:=password, _
no_mail:=True)
' Create a new message
Set objMessage = newMessage(objSession, address)
' Check how the address will be resolved
resolveAddress = resolveMsgAddress(objMessage)
If (resolveAddress = USOFT_UNRESOLVED_ADDRESS) Then
resolveAddress = original_address
End If
cleanUp objSession, objMessage
Exit Function
on_error:
If Not ignoreError() Then
resolve_address = original_address
showError "resolveAddress"
End If
cleanUp objSession, objMessage
End Function

This topic has been closed for comments