Share via


Adding Contact Information into Messages with CDOEX

Topic Last Modified: 2006-06-11

Example

Visual Basic

'Adding Contact Information into Messages with CDOEx

Private Sub Main()

   Dim strServerName As String
   Dim strDomainName As String
   Dim strRecipName As String
   Dim strURL As String
   Dim objContact As New CDO.Person

   'Create an LDAP query string to find the right contact "record".
   strServerName = "Server6"
   strDomainName = "DC=MYDOMAIN3,DC=example,DC=com"

   ' Alias
   strRecipName = "User1"


   'Get the contact from the server.
   objContact.DataSource.Open strURL

   If Err.Number = 0 Then

      'If there are no errors, continue and create a new message.
      Set objMessage = New CDO.Message

      ' The "With" statement reduces object reference overhead.
      With objMessage
         .Subject = "test message to contact"
         .TextBody = "This is a simple text message to a contact"
         .From = " <sender alias>"

         ' E-mail address of the contact that was found.
         .To = objContact.Email

         ' Use Exchange Server.
         .Configuration.Fields("cdoSendUsing") = cdoSendUsingExchange
         .Configuration.Fields.Update
         .Send
      End With
   End If

   'Release objects explicitly.
   Set objContact = Nothing
   Set objMessage = Nothing

 End Sub