• Welcome to Powerbasic Museum 2020-B.
 

News:

Forum in repository mode. No new members allowed.

Main Menu

CDO: Collaboration Data Objects

Started by José Roca, August 22, 2008, 05:31:27 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

José Roca

 
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.

José Roca

#1
 
The following example sends a simple text email that can be viewed in any email client.


' ########################################################################################
' 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
' ========================================================================================


José Roca

#2
 
The following example demonstrates how to send an HTML email using CDO.


' ########################################################################################
' 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
' ========================================================================================



José Roca

#3
 
The following example demonstrates how to send a web page from a remote site using CDO.


' ########################################################################################
' 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
' ========================================================================================


José Roca

#4
 
The following example demonstrates how to send a web page from a file in your computer using CDO.


' ########################################################################################
' 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
' ========================================================================================


José Roca

#5
 
The following example demonstrates how to send a text email with an attached file using CDO.


' ########################################################################################
' 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
' ========================================================================================


José Roca

#6
 
The following CDO example demonstrates how to send a text email and save a copy of it in the local system.


' ########################################################################################
' 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
' ========================================================================================