Example 2: Resolving an Email Address

Previous Next

See Also

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).

To try out this example:

· Locate the Samples/Usmail directory on your CD.

 

· Read the README.TXT file for information on installing, running and inspecting the sample component.

Component

USMAIL

Component Prog ID

UsMail.Class1

Method

RESOLVE_ADDRESS

Physical Method

resolveAddress

Parameters of RESOLVE_ADDRESS

1, In, String

2, Return, String

PERSON Table

Add an EMAIL column based on a regular CHAR(60) domain (On Oracle7: VARCHAR2).

Constraint

RESOLVE_EMAIL

UPDATE person

SET email =

(

   INVOKE usmail.resolve_address with

   SELECT email

)

WHERE email is not null

Description of functionality:

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