Powerbasic Museum 2020-B

Legacy Software (PBWIN 9.0+/PBCC 5.0+) => COM Programming (General) => Source Code => Topic started by: José Roca on August 22, 2008, 05:31:27 AM

Title: CDO: Collaboration Data Objects
Post by: José Roca 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.
Title: [CDO] Send a text email
Post by: José Roca on August 22, 2008, 05:34:05 AM
 
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
' ========================================================================================

Title: [CDO] Send an HTML email
Post by: José Roca on August 22, 2008, 05:35:32 AM
 
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
' ========================================================================================


Title: [CDO] Send a web page from a remote site
Post by: José Roca on August 22, 2008, 05:36:51 AM
 
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
' ========================================================================================

Title: [CDO] Send an web page from a file in your computer
Post by: José Roca 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.


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

Title: [CDO] Send a text email with an attachment
Post by: José Roca on August 22, 2008, 05:39:26 AM
 
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
' ========================================================================================

Title: [CDO] Sending and saving a text email
Post by: José Roca 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.


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