Platform SDK: Exchange 2000 Server

IMessage Interface

[This is preliminary documentation and subject to change.]

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

IID
CD000001-8B95-11D1-82DB-00C04FB1625D
Extends
IDispatch

Member Summary

Properties

Name Type Description
Attachments

(Read-Only)

[Visual Basic] IBodyParts

[C++,IDL]IBodyParts*

Returns the collection of attachments for this message.
AutoGenerateTextBody

[Visual Basic] Boolean

[C++,IDL] VARIANT_BOOL

Indicates whether the TextBody of a message should automatically be generated from the contents of the HTMLBody property for a multipart/alternative message.
BCC

[Visual Basic] String

[C++,IDL] BSTR

The blind carbon copy (Bcc) recipients for this message.
BodyPart

(Read-Only)

[Visual Basic] IBodyPart

[C++,IDL]IBodyPart*

Returns the IBodyPart interface on this object.
CC

[Visual Basic] String

[C++,IDL] BSTR

The informational (carbon copy, or Cc) recipients for this message.
Configuration

[Visual Basic]IConfiguration

[C++,IDL] IConfiguration

The Configuration object for the message.
DataSource

(Read-Only)

IDataSource

[C++,IDL]IDataSource*

The IDataSource interface on the object.
DSNOptions

[Visual Basic] CdoDSNOptions

[C++,IDL] CdoDSNOptions

The Delivery Status Notification (DSN) options for the message. These options include in the message a request for a return report on the delivery status of the message.
EnvelopeFields

(Read-Only)

[Visual Basic] ADODB.Fields

[C++,IDL] Fields*

A collection of fields associated with the SMTP or NNTP transport envelope of the message.
Fields

(Read-Only)

[Visual Basic] ADODB.Fields

[C++,IDL] Fields*

The object's Fields collection.
FollowUpTo

[Visual Basic] String

[C++,IDL] BSTR

The newsgroups to which any responses to this message should be posted.
From

[Visual Basic] String

[C++,IDL] BSTR

The address of the principal author of this message.
HTMLBody

[Visual Basic] String

[C++,IDL] BSTR

The HTML representation of the body of this message.
HTMLBodyPart

(Read-Only)

[Visual Basic] IBodyPart

[C++,IDL]IBodyPart*

Returns a reference to a BodyPart object in which the HTML content of this message is stored.
Keywords

[Visual Basic] String

[C++,IDL] BSTR

A list of keywords assigned to this message.
MDNRequested

[Visual Basic] Boolean

[C++,IDL] VARIANT_BOOL

Indicates whether a Message Disposition Notification (MDN) report is requested for the message.
MIMEFormatted

[Visual Basic] Boolean

[C++,IDL] VARIANT_BOOL

Indicates whether the message is to be formatted using Multipurpose Internet Mail Extensions (MIME).
Newsgroups

[Visual Basic] String

[C++,IDL] BSTR

The newsgroup recipients of the message.
Organization

[Visual Basic] String

[C++,IDL] BSTR

A description of the organization to which the sender belongs.
ReceivedTime

(Read-Only)

[Visual Basic] Date

[C++,IDL] DATE

Returns the date/time this message was delivered to the server.
ReplyTo

[Visual Basic] String

[C++,IDL] BSTR

The messaging address to which replies to this message should be sent.
Sender

[Visual Basic] String

[C++,IDL] BSTR

The messaging address of the submitter of this message.
SentOn

(Read-Only)

[Visual Basic] Date

[C++,IDL] DATE

Returns the date/time this message was submitted to the server.
Subject

[Visual Basic] String

[C++,IDL] BSTR

The subject of this message.
TextBody

[Visual Basic] String

[C++,IDL] BSTR

The plain text representation of the body of this message.
TextBodyPart

(Read-Only)

[Visual Basic] IBodyPart

[C++,IDL]IBodyPart*

Returns an IBodyPart object reference on the BodyPart object in which the text content of this message is stored.
To

[Visual Basic] String

[C++,IDL] BSTR

The principal (To) recipients for this message.

Methods

Name Description
AddAttachment Adds an attachment to this message.
AddRelatedBodyPart Adds a MHTML-related body part to the message's content.
CreateMHTMLBody Converts the contents of an entire Web page into MHTML-formatted body parts on this message
Forward Creates and returns another message that can be used to forward this message.
GetInterface Returns the specified dual interface on the object.
GetStream Returns the Stream object containing the complete message, including headers and all content, in serialized (wire-transport) format.
Post Submits this message to the specified newsgroups.
PostReply Creates and returns another message that can be used to post a reply to this message.
Reply Creates and returns another message that can be used to reply to the sender of this message.
ReplyAll Creates and returns another message that can be used to reply to the sender and all recipients.
Send Sends the message.

Remarks

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

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 normally also provide implementations of the IBodyPart and IDataSource interfaces. These interfaces can be retrieved 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 respectively, or by 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 if desired.

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.

Example

[Visual Basic]
Sub SendMessageExample1()

    Dim iMsg As New CDO.message
    Dim iBp As CDO.IBodyPart
    Dim Flds As ADODB.Fields
    Dim Stm As ADODB.Stream
    
    Dim iConf As New CDO.Configuration
    Set Flds = iConf.Fields
    Flds(cdoSendUsingMethod) = cdoSendUsingPort
    Flds(cdoSMTPServer) = "MySMTPServer"
    Flds(cdoSMTPServerPort) = 25
    Flds(cdoSMTPAuthenticate) = cdoAnonymous     ' 0
    Flds.Update
    
    With iMsg
     Set .Configuration = iConf
         .To = "someone@microsoft.com, another@microsoft.com"
         .From = "thirdperson@microsoft.com, fourth@microsoft.com"
         .Sender = "finally@microsoft.com"
         .Subject = "Files for Monday's meeting."
         .TextBody = "Please review the attached files for Monday's meeting.  Thanks." + vbLfCr + vbLfCr
    
      Set iBp = .AddAttachment(PATH & "mydocument.doc")
      Set Stm = iMsg.GetStream
      Stm.SaveToFile "c:\mysavedmessage.eml", adSaveCreateOverWrite
       .Send
    End With

End Sub
[C++,IDL]
IMessagePtr* CreateSampleMessage() {

   /*
   ** Assume these header files:
   ** #import <msado15.dll> no_namespace
   ** #import <cdoex.dll> no_namespace
   ** #include <iostream.h>
   */

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

   _bstr_t bstrEmpty("");

   pmsg = new IMessagePtr(__uuidof(Message));

   (*pmsg)->To      = "\"Some One\" <someone@microsoft.com>, \"Another\" <another@microsoft.com>";
   (*pmsg)->From      = "\"ThirdPerson\" <thirdperson@microsoft.com>, \"Fourth\" <fourth@microsoft.com>";
   (*pmsg)->Sender   = "\"Finally\" <finally@microsoft.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 = (*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.microsoft.com"),cdoSuppressAll,_bstr_t(""),_bstr_t(""));
   }
   catch(...) {
      throw;
   }

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

   return pmsg;
}
[VBScript]
Sub SendMessageExample1()

    ' PATH is the absolute path to the resource in the code below
    Dim iMsg
    Set iMsg = CreateObject("CDO.Message")
    Dim iBp
    Dim Flds
    Dim Stm
    
    Dim iConf
    Set iConf = CreateObject("CDO.Configuration")
    Set Flds = iConf.Fields

    Const cdoSendUsingMethod  = "http://schemas.microsoft.com/cdo/configuration/sendusing"
    Const cdoSMTPServer       = "http://schemas.microsoft.com/cdo/configuration/smtpserver"
    Const cdoSMTPServerPort   = "http://schemas.microsoft.com/cdo/configuration/smtpserverport"
    Const cdoSMTPAuthenticate = "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"
    Const cdoSendUsingPort    = 2
    Const cdoAnonymous        = 0
    Const adSaveCreateOverWrite = 2

    Flds(cdoSendUsingMethod) = cdoSendUsingPort
    Flds(cdoSMTPServer) = "MySMTPServer"
    Flds(cdoSMTPServerPort) = 25
    Flds(cdoSMTPAuthenticate) = cdoAnonymous     ' 0
    Flds.Update
    
    With iMsg
     Set .Configuration = iConf
         .To = "someone@microsoft.com, another@microsoft.com"
         .From = "thirdperson@microsoft.com, fourth@microsoft.com"
         .Sender = "finally@microsoft.com"
         .Subject = "Files for Monday's meeting."
         .TextBody = "Please review the attached files for Monday's meeting.  Thanks." + vbLfCr + vbLfCr
    
      Set iBp = .AddAttachment(PATH & "mydocument.doc")
      Set Stm = iMsg.GetStream
      Stm.SaveToFile "c:\mysavedmessage.eml", adSaveCreateOverWrite
       .Send
    End With

End Sub