Deprecated: Array and string offset access syntax with curly braces is deprecated in /homepages/21/d38531796/htdocs/jose/smfforum/Sources/Subs.php on line 3825
CDO: Collaboration Data Objects

Author Topic: CDO: Collaboration Data Objects  (Read 10230 times)

0 Members and 1 Guest are viewing this topic.

Offline José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2487
  • User-Rate: +204/-0
CDO: Collaboration Data Objects
« on: August 22, 2008, 05:31:27 AM »
 
Collaboration Data Objects (CDO) is a COM wrapper of the MAPI library. CDO implements most but not all MAPI functionality, although far more than Simple MAPI.

CDO for Exchange Server (CDOEX) provides the fundamental Component Object Model (COM) classes and interfaces that are used to manage most types of information in the Exchange store.

CDOSYS is a proper subset of the functionality offered by CDO for Exchange, so all applications will continue to function properly. When Microsoft Exchange installed, CDOSYS.DLL is unregistered from the system and COM runtime.

Both components share a common set of GUID values, interface definitions, module constants and so on. Applications do not need to be recompiled.

If you use CDOEX to develop an application that will also run without Microsoft Exchange Server, you can only use the following ProgIDs, interfaces, collections, enumerations and events:

ProgIDs: CDO.Configuration.1, CDO.DropDirectory.1, CDO.Message.1.

Interfaces: IBodyPart, IConfiguration, IDataSource, IDropDirectory, IMessage.

Collections: IBodyParts, IMessages.

Enumerations: CdoConfigSource, CdoDSNOptions, CdoEventStatus, CdoImportanceValues, CdoMessageStat, CdoMHTMLFlags, CdoNNTProcessingField, CdoPostUsing, CdoPriorityValues, CdoProtocolsAithentication, CdoReferenceType, CdoSendUsing, CdoSensitivityValues, CdoTimeZoneId.
« Last Edit: August 22, 2008, 07:46:59 AM by José Roca »

Offline José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2487
  • User-Rate: +204/-0
[CDO] Send a text email
« Reply #1 on: August 22, 2008, 05:34:05 AM »
 
The following example sends a simple text email that can be viewed in any email client.

Code: [Select]
' ########################################################################################
' This sample sends a simple text email that can be viewed in any email client.
' ########################################################################################

' SED_PBWIN - Use the PBWin compiler
#COMPILE EXE
#DIM ALL
#INCLUDE ONCE "CDOSYS.INC"
#INCLUDE ONCE "OLE2UTILS.INC"

' ========================================================================================
' Main
' ========================================================================================
FUNCTION PBMAIN () AS LONG

   LOCAL pMessage AS CDO_IMessage   ' // CDOSYS - IMessage interface

   ' // Create an instance of the CDO Message interface
   pMessage = NEWCOM("CDO.Message")
   IF ISNOTHING(pMessage) THEN EXIT FUNCTION

   TRY
      ' // Recipient name --> change as needed
      pMessage.To = UCODE$("joseroca.daman@ono.com")
      ' // Sender name --> change as needed
      pMessage.From = UCODE$("JRoca@com.it-berater.org")
      ' // Subject --> change as needed
      pMessage.Subject = UCODE$("This is a sample subject")
      ' // Text body --> change as needed
      pMessage.TextBody = UCODE$("This is a sample body")
      ' // Send the message
      pMessage.Send
      MSGBOX "Message sent"
   CATCH
      ' // Display the error message
      OleShowErrorInfo OBJRESULT
   FINALLY
      ' // Release the Message object
      pMessage = NOTHING
   END TRY

END FUNCTION
' ========================================================================================
« Last Edit: August 07, 2011, 05:31:33 AM by José Roca »

Offline José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2487
  • User-Rate: +204/-0
[CDO] Send an HTML email
« Reply #2 on: August 22, 2008, 05:35:32 AM »
 
The following example demonstrates how to send an HTML email using CDO.

Code: [Select]
' ########################################################################################
' Sending an HTML email using CDO
' ########################################################################################

' SED_PBWIN - Use the PBWin compiler
#COMPILE EXE
#DIM ALL
#INCLUDE ONCE "CDOSYS.INC"
#INCLUDE ONCE "OLE2UTILS.INC"

' ========================================================================================
' Main
' ========================================================================================
FUNCTION PBMAIN () AS LONG

   LOCAL pMessage AS CDO_IMessage   ' // CDOSYS - IMessage interface

   ' // Create an instance of the CDO Message interface
   pMessage = NEWCOM("CDO.Message")
   IF ISNOTHING(pMessage) THEN EXIT FUNCTION

   TRY
      ' // Recipient name --> change as needed
      pMessage.To = UCODE$("joseroca.daman@ono.com")
      ' // Sender name --> change as needed
      pMessage.From = UCODE$("JRoca@com.it-berater.org")
      ' // Subject --> change as needed
      pMessage.Subject = UCODE$("This is a sample subject")
      ' // HTML body --> change as needed
      pMessage.HTMLBody = UCODE$("<h1>This is sample HTML body.</h1>")
      ' // Send the message
      pMessage.Send
      MSGBOX "Message sent"
   CATCH
      ' // Display the error message
      OleShowErrorInfo OBJRESULT
   FINALLY
      ' // Release the Message object
      pMessage = NOTHING
   END TRY

END FUNCTION
' ========================================================================================

« Last Edit: August 07, 2011, 05:31:48 AM by José Roca »

Offline José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2487
  • User-Rate: +204/-0
[CDO] Send a web page from a remote site
« Reply #3 on: August 22, 2008, 05:36:51 AM »
 
The following example demonstrates how to send a web page from a remote site using CDO.

Code: [Select]
' ########################################################################################
' CDO - Sending a web page from a remote site
' ########################################################################################

' SED_PBWIN - Use the PBWin compiler
#COMPILE EXE
#DIM ALL
#INCLUDE ONCE "CDOSYS.INC"
#INCLUDE ONCE "OLE2UTILS.INC"

' ========================================================================================
' Main
' ========================================================================================
FUNCTION PBMAIN () AS LONG

   LOCAL pMessage AS CDO_IMessage   ' // CDOSYS - IMessage interface

   ' // Create an instance of the CDO Message interface
   pMessage = NEWCOM("CDO.Message")
   IF ISNOTHING(pMessage) THEN EXIT FUNCTION

   TRY
      ' // Recipient name --> change as needed
      pMessage.To = UCODE$("joseroca.daman@ono.com")
      ' // Sender name --> change as needed
      pMessage.From = UCODE$("JRoca@com.it-berater.org")
      ' // Subject --> change as needed
      pMessage.Subject = UCODE$("This is a sample subject")
      ' // MHTMLBody --> change as needed
      pMessage.CreateMHTMLBody UCODE$("http://www.jose.it-berater.org/index.html")
      ' // Send the message
      pMessage.Send
      MSGBOX "Message sent"
   CATCH
      ' // Display the error message
      OleShowErrorInfo OBJRESULT
   FINALLY
      ' // Release the Message object
      pMessage = NOTHING
   END TRY

END FUNCTION
' ========================================================================================
« Last Edit: August 07, 2011, 05:32:01 AM by José Roca »

Offline José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2487
  • User-Rate: +204/-0
[CDO] Send an web page from a file in your computer
« Reply #4 on: August 22, 2008, 05:38:03 AM »
 
The following example demonstrates how to send a web page from a file in your computer using CDO.

Code: [Select]
' ########################################################################################
' CDO - Sending a web page from a file in your computer
' ########################################################################################

' SED_PBWIN - Use the PBWin compiler
#COMPILE EXE
#DIM ALL
#INCLUDE ONCE "CDOSYS.INC"
#INCLUDE ONCE "OLE2UTILS.INC"

' ========================================================================================
' Main
' ========================================================================================
FUNCTION PBMAIN () AS LONG

   LOCAL pMessage AS CDO_IMessage   ' // CDOSYS - IMessage interface

   ' // Create an instance of the CDO Message interface
   pMessage = NEWCOM("CDO.Message")
   IF ISNOTHING(pMessage) THEN EXIT FUNCTION

   TRY
      ' // Recipient name --> change as needed
      pMessage.To = UCODE$("joseroca.daman@ono.com")
      ' // Sender name --> change as needed
      pMessage.From = UCODE$("JRoca@com.it-berater.org")
      ' // Subject --> change as needed
      pMessage.Subject = UCODE$("This is a sample subject")
      ' // MHTMLBody --> change as needed
      pMessage.CreateMHTMLBody UCODE$("file://c:/temp/Test.html")
      ' // Send the message
      pMessage.Send
      MSGBOX "Message sent"
   CATCH
      ' // Display the error message
      OleShowErrorInfo OBJRESULT
   FINALLY
      ' // Release the Message object
      pMessage = NOTHING
   END TRY

END FUNCTION
' ========================================================================================
« Last Edit: August 07, 2011, 05:32:14 AM by José Roca »

Offline José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2487
  • User-Rate: +204/-0
[CDO] Send a text email with an attachment
« Reply #5 on: August 22, 2008, 05:39:26 AM »
 
The following example demonstrates how to send a text email with an attached file using CDO.

Code: [Select]
' ########################################################################################
' CDO - Sending a text email with an attached file.
' ########################################################################################

' SED_PBWIN - Use the PBWin compiler
#COMPILE EXE
#DIM ALL
#INCLUDE ONCE "CDOSYS.INC"
#INCLUDE ONCE "OLE2UTILS.INC"

' ========================================================================================
' Main
' ========================================================================================
FUNCTION PBMAIN () AS LONG

   LOCAL pMessage AS CDO_IMessage   ' // CDOSYS - IMessage interface

   ' // Create an instance of the CDO Message interface
   pMessage = NEWCOM("CDO.Message")
   IF ISNOTHING(pMessage) THEN EXIT FUNCTION

   TRY
      ' // Recipient name --> change as needed
      pMessage.To = UCODE$("joseroca.daman@ono.com")
      ' // Sender name --> change as needed
      pMessage.From = UCODE$("JRoca@com.it-berater.org")
      ' // Subject --> change as needed
      pMessage.Subject = UCODE$("This is a sample subject")
      ' // Text body --> change as needed
      pMessage.TextBody = UCODE$("This is a sample message text")
      ' // Add the attachment (use absolute paths).
      ' // Note  By repeating the call you can add attach more than one file.
      pMessage.AddAttachment UCODE$(EXE.Path$ & "EX_CDO_01.BAS")
      ' // Send the message
      pMessage.Send
      MSGBOX "Message sent"
   CATCH
      ' // Display the error message
      OleShowErrorInfo OBJRESULT
   FINALLY
      ' // Release the Message object
      pMessage = NOTHING
   END TRY

END FUNCTION
' ========================================================================================
« Last Edit: August 07, 2011, 05:32:32 AM by José Roca »

Offline José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2487
  • User-Rate: +204/-0
[CDO] Sending and saving a text email
« Reply #6 on: August 22, 2008, 05:40:56 AM »
 
The following CDO example demonstrates how to send a text email and save a copy of it in the local system.

Code: [Select]
' ########################################################################################
' CDO - Sending a text email and saving a copy in the local system
' ########################################################################################

' SED_PBWIN - Use the PBWin compiler
#COMPILE EXE
#DIM ALL
#INCLUDE ONCE "CDOSYS.INC"
#INCLUDE ONCE "OLE2UTILS.INC"

' ========================================================================================
' Main
' ========================================================================================
FUNCTION PBMAIN () AS LONG

   LOCAL pMessage AS CDO_IMessage   ' // CDOSYS - IMessage interface
   LOCAL pStream AS ADOStream       ' // ADO    - Stream object

   ' // Create an instance of the CDO Message interface
   pMessage = NEWCOM("CDO.Message")
   IF ISNOTHING(pMessage) THEN EXIT FUNCTION

   TRY
      ' // Recipient name --> change as needed
      pMessage.To = UCODE$("joseroca.daman@ono.com")
      ' // Sender name --> change as needed
      pMessage.From = UCODE$("JRoca@com.it-berater.org")
      ' // Subject --> change as needed
      pMessage.Subject = UCODE$("This is a sample subject")
      ' // Text body --> change as needed
      pMessage.TextBody = UCODE$("This is a sample message text")
      ' Save a copy of the message to the local file system
      pStream = pMessage.GetStream
      ' Note Using adSaveCreateOverWrite may overwrite an existing item of the same name.
      pStream.SaveToFile UCODE$("savemymessage.eml"), %adSaveCreateOverWrite
      ' Close and release the stream
      pStream.Close
      pStream = NOTHING
      ' // Send the message
      pMessage.Send
      MSGBOX "Message sent"
   CATCH
      ' // Display the error message
      OleShowErrorInfo OBJRESULT
   FINALLY
      ' // Release the Message object
      pMessage = NOTHING
   END TRY

END FUNCTION
' ========================================================================================
« Last Edit: August 22, 2008, 06:33:35 AM by José Roca »