IMessage Interface

IMessage Interface

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)

IBodyParts

IBodyParts *

The collection of message attachments.

AutoGenerateTextBody

Boolean

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

String

BSTR

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

BodyPart

(Read-only)

IBodyPart

IBodyPart *

The IBodyPart interface on this object.

CC

String

BSTR

The secondary (Cc) recipients for this message.

Configuration

Configuration

IConfiguration*

The Configuration object that is associated with the Message object.

DataSource

(Read-only)

IDataSource

IDataSource *

The IDataSource interface on this object.

DSNOptions

CdoDSNOptions

CdoDSNOptions

Includes a request for a return report on the delivery status of the message.

EnvelopeFields

(Read-only)

ADODB.Fields

Fields*

The Simple Mail Transfer Protocol (SMTP) or Network News Transfer Protocol (NNTP) transport envelope fields of the message. Only available with messages passed to transport event sinks.

Fields

(Read-only)

ADODB.Fields

Fields*

The Fields collection for the object.

FollowUpTo

String

BSTR

Newsgroups to which any responses to this message are posted.

From

String

BSTR

The messaging address of the principal author of the message.

HTMLBody

String

BSTR

The Hypertext Markup Language (HTML) representation of the message.

HTMLBodyPart

(Read-only)

IBodyPart

IBodyPart*

An IBodyPart object reference on the BodyPart object in which the HTML content of this message is stored.

Keywords

String

BSTR

The list of keywords for this message.

MDNRequested

Boolean

VARIANT_BOOL

Indicates whether a Message Disposition Notification is requested on a message.

MIMEFormatted

Boolean

VARIANT_BOOL

Indicates whether this message is to be formatted as multipart/alternative.

Newsgroups

String

BSTR

The newsgroup recipients for the message.

Organization

String

BSTR

The organization of the sender.

ReceivedTime

(Read-only)

Date

DATE

The date and time that the message is received.

ReplyTo

String

BSTR

The messaging addresses to which replies to this message should be sent.

Sender

String

BSTR

The messaging address of the message submitter.

SentOn

(Read-only)

Date

DATE

The date and time the message was sent.

Subject

String

BSTR

The message subject.

TextBody

String

BSTR

The plain text representation of the message.

TextBodyPart

(Read-only)

IBodyPart

IBodyPart *

An IBodyPart object reference on the BodyPart object that contains the plain text representation of the message.

To

String

BSTR

The principal (To) recipients for this message.

Methods

Name Description

AddAttachment

Adds an attachment to this message.

AddRelatedBodyPart

Adds a body part related to MIME Encapsulation of Aggregate HTML Documents (MHTML) part to the message's content.

CreateMHTMLBody

Converts the contents of an entire Web page into body parts formatted in MHTML 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 of this message.

Send

Sends the message.

Remarks

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

  • Address messages and otherwise define the top-level message headers using interface properties or the Fields collection.
  • Create or modify the message content, including content formatted in Multipurpose Internet Mail Extensions (MIME)
  • Retrieve the message as a stream encoded in 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 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 (respectively) on this interface, 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.

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 methods such as AddAttachment and CreateMHTMLBody are examples of the second.

The specific actions for methods such as Send or Post are defined using configuration fields that are contained within an associated Configuration object (IConfiguration interface).

Example

' Reference to Microsoft ActiveX Data Objects 2.5 Library
' Reference to Microsoft CDO for Windows 2000 Library
Dim iMsg as New CDO.Message
Dim iBp as CDO.IBodyPart
Dim Flds as ADODB.Fields

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          = "example@example.com, another@example.com"
     .From        = "exampleuser3@example.com, exampleuser4@example.com"
     .Sender      = "example@example.com"
     .Subject     = "Files for Monday's meeting."
     .TextBody    = "Please review the attached files for Monday's meeting.  Thanks." + vbLfCr + vbLfCr

  Set iBp =  .AddAttachment("c:\somefile.doc")
  iBp.ContentMediaType="application/msword"
  Set iBp =  .AddAttachment("c:\anotherfile.html")
  iBp.ContentMediaType="text/html"

  .Send
End With
#import <cdosys.dll> no_namespace raw_interfaces_only
#import "d:\program files\common files\system\ado\msado15.dll" no_namespace raw_interfaces_only
#include "cdosysstr.h"
#include "cdosyserr.h"

main() {

  CoInitialize(NULL);

  IMessage*       pMsg    = NULL;
  IBodyPart*      pBp     = NULL;
  IConfiguration* pConfig = NULL;
  Fields*         pFlds   = NULL;
  Field*          pFld    = NULL;
  _Stream*        pStm    = NULL;

  HRESULT hr = S_OK;

  hr=CoCreateInstance(
       __uuidof(Message),
       NULL,
       CLSCTX_INPROC_SERVER,
       __uuidof(IMessage),
       (void**)&pMsg);

  pMsg->put_To(_bstr_t("\"Some One\" <example@example.com>, \"Another\" <another@example.com>"));
  pMsg->put_From(_bstr_t("\"ThirdPerson\" <exampleuser3@example.com>, \"Fourth\" <exampleuser4@example.com>"));
  pMsg->put_Sender(_bstr_t("\Finally\" <example@example.com>"));
  pMsg->put_Subject(_bstr_t("Files for Monday's meeting."));
  pMsg->put_TextBody(_bstr_t("Please review the attached files for Monday's meeting.  Thanks. \r\n\r\n"));

  pMsg->AddAttachment(L"c:\somefile.doc",L"",L"",&pBp);
  pBp->put_ContentMediaType(L"application/msword");
  pBp->Release();
  pBp = NULL;

  pMsg->AddAttachment(L"c:\anotherfile.html",L"",L"",&pBp);
  pBp->put_ContentMediaType(L"text/html");
  pBp->Release();
  pBp = NULL;

  CoCreateInstance(
       __uuidof(Configuration),
       NULL,
       CLSCTX_INPROC_SERVER,
       __uuidof(IConfiguration),
       (void**)&pConfig);

  pConfig->get_Fields(&pFlds);

  pFlds->get_Item(_variant_t(cdoSendUsingMethod),&pFld);
  pFld->put_Value(_variant_t((long)cdoSendUsingPort));
  pFld->Release();
  pFld=NULL;

  pFlds->get_Item(_variant_t(cdoSMTPServer),&pFld);
  pFld->put_Value(_variant_t("MySMTPServer"));
  pFld->Release();
  pFld=NULL;

  pFlds->get_Item(_variant_t(cdoSMTPServerPort),&pFld);
  pFld->put_Value(_variant_t((long)25));
  pFld->Release();
  pFld=NULL;

  pFlds->get_Item(_variant_t(cdoSMTPAuthenticate),&pFld);
  pFld->put_Value(_variant_t((long)cdoAnonymous)); // 0
  pFld->Release();
  pFld=NULL;

  pFlds->Update();
  pFlds->Release();
  pFlds=NULL;

  pMsg->putref_Configuration(pConfig);
  pConfig->Release();
  pConfig=NULL;

  pMsg->GetStream(&pStm);
  pStm->SaveToFile(L"c:\\savemymessage.eml",adSaveCreateOverWrite);

  pMsg->Send();

  pStm->Release();
  pMsg->Release();

  CoUninitialize();
}
Dim iMsg
Set iMsg = CreateObject("CDO.Message")
Dim iBp
Dim Flds

Dim iConf
Set iConf = CreateObject("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          = "example@example.com, another@example.com"
     .From        = "exampleuser3@example.com, exampleuser4@example.com"
     .Sender      = "example@example.com"
     .Subject     = "Files for Monday's meeting."
     .TextBody    = "Please review the attached files for Monday's meeting.  Thanks." + vbLfCr + vbLfCr

  Set iBp =  .AddAttachment("c:\somefile.doc")
  iBp.ContentMediaType="application/msword"
  Set iBp =  .AddAttachment("c:\anotherfile.html")
  iBp.ContentMediaType="text/html"

  .Send
End With