Export (0) Print
Expand All
4 out of 24 rated this helpful - Rate this topic

IMessage Interface

Exchange Server 2003
The IMessage interface defines methods and properties used to manage messages.

CLSID

CD000020-8B95-11D1-82DB-00C04FB1625D

Extends

IDispatch

Type Library

Microsoft CDO for Exchange 2000 Library

DLL Implemented In

CDOEX.DLL

Member Summary

The following table lists the properties of the IMessage interface.

NameDescription
AttachmentsThe Attachments property specifies the collection of attachments for this message. This property is read-only.
AutoGenerateTextBodyIndicates whether the TextBody of a message should automatically be generated from the contents of the HTMLBody property for a multipart/alternative message.
BCCThe blind carbon copy (Bcc) recipients for this message.
BodyPartThe IBodyPart interface on this object. This property is read-only.
CCThe informational carbon copy (Cc) recipients for this message.
ConfigurationThe Configuration object for the message.
DataSourceThe IDataSource interface on this object. This property is read-only.
DSNOptionsThe Delivery Status Notification (DSN) options for the message.
EnvelopeFieldsThe SMTP and Network News Transfer Protocol (NNTP) envelope fields of the message. This property is read-only.
FieldsThe Fields collection for the object. This property is read-only.
FollowUpToThe newsgroups to which any responses to this message should be posted.
FromThe e-mail addresses of the principal author or authors of this message.
HTMLBodyThe HTML representation of the message.
HTMLBodyPartThe BodyPart object containing the HTML representation of the message. This property is read-only.
KeywordsA list of keywords for this message.
MDNRequestedIndicates whether a Mail Delivery Notification (MDN) report is requested for a message.
MimeFormattedIndicates whether or not this message is to be formatted using the Multipurpose Internet Mail Extensions (MIME) formatting scheme.
NewsgroupsThe newsgroup recipients for the message.
OrganizationContains a description of the organization to which the sender belongs.
ReceivedTimeThe date/time this message was delivered to the server. This property is read-only.
ReplyToThe address to which replies should be sent.
SenderThe address of the user or agent that actually submits the message.
SentOnThe date/time this message was submitted to the server. This property is read-only.
SubjectThe subject of the message.
TextBodyThe plain text representation of the body of this message.
TextBodyPartReturns a body part object containing the text content of this message. This property is read-only.
ToContains a list of principal (To) recipients for this message.

The following table lists the methods of the IMessage interface.

NameDescription
AddAttachmentAdds an attachment to this message.
AddRelatedBodyPartThe AddRelatedBodyPart method adds a BodyPart object that is referenced by content in the HTML body of the message.
CreateMHTMLBodyThe CreateMHTMLBody method converts the contents of an entire Web page into a MIME Encapsulation of Aggregate HTML Documents (MHTML) formatted message body.
ForwardThe Forward method creates and returns another message that can be used to forward this message.
GetInterfaceReturns the specified dual interface on the object.
GetStreamThe GetStream method returns this message in serialized (wire-transport) format in a Microsoft® ActiveX® Data Objects (ADO) Stream object.
PostThe Post method posts this message to the specified newsgroups.
PostReplyThe PostReply method creates and returns another message that can be used to post a reply to this message.
ReplyThe Reply method creates and returns another message that can be used to reply to the sender of this message.
ReplyAllThe ReplyAll method creates and returns another message that can be used to reply to the sender and all recipients.
SendThe Send method sends the message.

Remarks

The IMessage interface defines methods and properties used by implementing objects to provide messaging functionality. Component Object Model (COM) classes that provide an implementation of the IMessage interface should allow you to:

  • Address messages and otherwise define the top-level message headers either using interface properties or through the Fields collection.
  • Create and/or modify the message content, including MIME-formatted content.
  • Retrieve the message as a stream encoded using MIME or UUENCODE using the GetStream method.
  • Send or post messages, and respond to existing messages.

Address messages and otherwise define the top-level message headers either using interface properties or through the Fields collection. Create and/or modify the message content, including MIME-formatted content. Retrieve the message as a stream encoded using MIME or UUENCODE using the GetStream method. Send or post messages, and respond to existing messages.

All mail headers are available generically through the Fields collection. The most common mail headers, such as To, From, Cc, and Subject, are directly available on the interface.

COM classes that provide implementations of the IMessage interface should also provide implementations of the IBodyPart and IDataSource interfaces. These interfaces can be retrieved in the following ways:

  • Using the standard interface navigation mechanisms, such as QueryInterface in C++ and the Set keyword in Microsoft Visual Basic®
  • Through the Bodypart and DataSource properties on this interface
  • Using the GetInterface method

Using the standard interface navigation mechanisms, such as QueryInterface in C++ and the Set keyword in Visual Basic Through the Bodypart and DataSource properties on this interface Using the GetInterface method

The GetInterface method is intended primarily to provide scripting languages that do not inherently support interface navigation a means to do so. However, the method can be used from any language.

The methods on the IMessage interface fall into two general categories: those used to send, post, or respond to messages, and those used as aids when creating message content. Methods such as Send, Post, and Reply are examples of the first category, and AddAttachment and CreateMHTMLBody are examples of the second.

The specific behavior for methods such as Send or Post is defined using configuration fields contained within an associated Configuration object.

Examples

[Visual Basic]

' Reference to CDO for Exchange 2000 Library
' Reference to ActiveX Data Objects 2.5 Library
' Reference to Active DS Type Library

Sub Main()

    Dim Info As New ADSystemInfo
    Dim InfoNT As New WinNTSystemInfo
    Dim iPer As New CDO.Person
    Dim sTo As String
    Dim sFrom As String
    Dim sSubject As String
    Dim sText As String

    sTo = InfoNT.UserName & "@" & Info.DomainDNSName
    sFrom = sTo
    sSubject = "Subject"
    sText = "Text of message."

    iPer.DataSource.Open "LDAP://" & Info.UserName

    Dim iMbx As CDO.IMailbox
    Set iMbx = iPer

    SendMessageUsingExchange sTo, sFrom, sSubject, sText, iMbx.BaseFolder

End Sub

Sub SendMessageUsingExchange(sTo As String, sFrom As String, sSubject As String, sText As String, sMailboxURL As String)

    Dim iMsg As New CDO.Message
    Dim iBp As CDO.IBodyPart
    Dim Flds As ADODB.Fields
    Dim Conn As New ADODB.Connection
    Dim Stm As ADODB.Stream

    Conn.Provider = "ExOLEDB.DataSource"
    Conn.Open sMailboxURL

    Dim iConf As New CDO.Configuration
    Set Flds = iConf.Fields

    Flds(cdoSendUsingMethod) = cdoSendUsingExchange
    Flds(cdoMailboxURL) = sMailboxURL
    Flds(cdoActiveConnection) = Conn
    Flds.Update

    With iMsg
     Set .Configuration = iConf
         .To = sTo
         .From = sFrom
         .Subject = sSubject
         .TextBody = sText

      Set iBp = .AddAttachment("c:\wordfile.doc")
      Set Stm = .GetStream
      Stm.SaveToFile "c:\mysavedmessage.eml", adSaveCreateOverWrite
        .Send
    End With

End Sub

[C++,IDL]

 /*
  You must have the following paths in your
  include path:
  %CommonProgramFiles%\system\ado
  %CommonProgramFiles%\microsoft shared\cdo
  are in the INCLUDE path.
  Import the type libraries into the project:

  #import <msado15.dll> no_namespace raw_interfaces_only
  #import <cdoex.dll>   no_namespace raw_interfaces_only

 */
#ifndef _CORE_EXAMPLE_HEADERS_INCLUDED
#define _CORE_EXAMPLE_HEADERS_INCLUDED
#import <msado15.dll> no_namespace
#import <cdoex.dll> no_namespace
#include <iostream.h>
#endif

IMessagePtr CreateSampleMessage() {

   IMessagePtr         pmsg(__uuidof(Message));
   IBodyPartPtr      bp;
   IConfigurationPtr   config(__uuidof(Configuration));
   FieldsPtr         flds;
   FieldPtr         fld;
   _StreamPtr         stm;

   _bstr_t bstrEmpty("");

   pmsg->To      = "\"Some One\" <someone@example.com>, \"Another\" <another@example.com>";
   pmsg->From      = "\"ThirdPerson\" <thirdperson@example.com>, \"Fourth\" <fourth@example.com>";
   pmsg->Sender   = "\"Finally\" <finally@example.com>";
   pmsg->Subject   =   "A really cool message.";

   /*
   ** Get current directory so that relative paths
   ** can be expanded. This is needed for AddAttachment.
   */

   LPTSTR buf = NULL;
   DWORD buflen = 0;
   _bstr_t path;
   if( ( buflen = GetCurrentDirectory(buflen,NULL) ) > 0 ) {
      buf = new TCHAR[buflen+1];
      GetCurrentDirectory(buflen+1,buf);
      path = buf;
      delete [] buf;
   }
   else {
      cerr << "Error getting current directory" << endl;;
      throw _com_error(GetLastError());
   }

   try {
      bp = pmsg->AddAttachment(path + _bstr_t("\\..\\misc\\wordfile.doc"),
                           bstrEmpty,
                           bstrEmpty);

      bp->Fields->Item["urn:schemas:mailheader:content-type"]->Value = variant_t("application/msword");
      bp->Fields->Update();
      bp = pmsg->AddAttachment(path + _bstr_t("\\..\\misc\\message2.eml"),
                           bstrEmpty,
                           bstrEmpty);
      bp->Fields->Item["urn:schemas:mailheader:content-type"]->Value = _variant_t("message/rfc822");
      bp->Fields->Update();

      pmsg->CreateMHTMLBody(_bstr_t("http://msdn.example.com"),cdoSuppressAll,_bstr_t(""),_bstr_t(""));
   }
   catch(_com_error e) {
      cerr << "Error creating sample message!" << endl;
      throw e;
   }

   // Save a copy to the local file system.
   stm = pmsg->GetStream();
   stm->SaveToFile(_bstr_t("savemymessage.eml"),adSaveCreateOverWrite);

   return pmsg;
}

[VBScript]

' WSH Source file.
' Assume
'   <reference object="adodb.record"/>
'   <reference object="cdo.message"/>
' exist to resolve type names using the
' type libraries.

Sub SendMessageUsingExchange( sTo, sFrom, sSubject, sText, sMailboxURL)

    Dim iMsg
    Set iMsg = CreateObject("CDO.Message")
    Dim iBp
    Dim Flds
    Dim Conn
    Dim Stm
    Set Conn = CreateObject("ADODB.Connection")
    Conn.Provider = "ExOLEDB.DataSource"
    Conn.Open sMailboxURL
    
    Dim iConf
    Set iConf = CreateObject("CDO.Configuration")
    Set Flds = iConf.Fields

    Flds(cdoSendUsingMethod)  = cdoSendUsingExchange ' 3
    Flds(cdoMailboxURL)       = sMailboxURL
    Flds(cdoActiveConnection) = Conn
    Flds.Update
    
    With iMsg
     Set .Configuration = iConf
         .To       = sTo
         .From     = sFrom
         .Subject  = sSubject
         .TextBody = sText
    
      Set iBp = .AddAttachment("c:\wordfile.doc")
      Set Stm = .GetStream
      Stm.SaveToFile "c:\mysavedmessage.eml", adSaveCreateOverWrite ' 2
        .Send
    End With

End Sub

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.