Platform SDK: CDO for Windows 2000 |
The IMessage interface defines methods and properties used to manage messages.
Properties
Name | Type | Description |
---|---|---|
Attachments
(Read-only) |
[Visual Basic] IBodyParts [C++,IDL] IBodyParts * |
The collection of message attachments. |
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 * |
The IBodyPart interface on this object. |
CC | [Visual Basic] String [C++,IDL] BSTR |
The secondary (Cc) recipients for this message. |
Configuration | [Visual Basic]Configuration [C++,IDL] IConfiguration* |
The Configuration object that is associated with the Message object. |
DataSource
(Read-only) |
[Visual Basic] IDataSource [C++,IDL] IDataSource * |
The IDataSource interface on this object. |
DSNOptions | [Visual Basic] CdoDSNOptions [C++,IDL] CdoDSNOptions |
Includes a request for a return report on the delivery status of the message. |
EnvelopeFields
(Read-only) |
[Visual Basic] ADODB.Fields [C++,IDL] 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) |
[Visual Basic] ADODB.Fields [C++,IDL] Fields* |
The Fields collection for the object. |
FollowUpTo | [Visual Basic] String [C++,IDL] BSTR |
Newsgroups to which any responses to this message are posted. |
From | [Visual Basic] String [C++,IDL] BSTR |
The messaging address of the principal author of the message. |
HTMLBody | [Visual Basic] String [C++,IDL] BSTR |
The Hypertext Markup Language (HTML) representation of the message. |
HTMLBodyPart
(Read-only) |
[Visual Basic] IBodyPart [C++,IDL] IBodyPart* |
An IBodyPart object reference on the BodyPart object in which the HTML content of this message is stored. |
Keywords | [Visual Basic] String [C++,IDL] BSTR |
The list of keywords for this message. |
MDNRequested | [Visual Basic] Boolean [C++,IDL] VARIANT_BOOL |
Indicates whether a Message Disposition Notification is requested on a message. |
MIMEFormatted | [Visual Basic] Boolean [C++,IDL] VARIANT_BOOL |
Indicates whether this message is to be formatted as multipart/alternative. |
Newsgroups | [Visual Basic] String [C++,IDL] BSTR |
The newsgroup recipients for the message. |
Organization | [Visual Basic] String [C++,IDL] BSTR |
The organization of the sender. |
ReceivedTime
(Read-only) |
[Visual Basic] Date [C++,IDL] DATE |
The date and time that the message is received. |
ReplyTo | [Visual Basic] String [C++,IDL] BSTR |
The messaging addresses to which replies to this message should be sent. |
Sender | [Visual Basic] String [C++,IDL] BSTR |
The messaging address of the message submitter. |
SentOn
(Read-only) |
[Visual Basic] Date [C++,IDL] DATE |
The date and time the message was sent. |
Subject | [Visual Basic] String [C++,IDL] BSTR |
The message subject. |
TextBody | [Visual Basic] String [C++,IDL] BSTR |
The plain text representation of the message. |
TextBodyPart
(Read-only) |
[Visual Basic] IBodyPart [C++,IDL] IBodyPart * |
An IBodyPart object reference on the BodyPart object that contains the plain text representation of the message. |
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 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. |
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:
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).
' 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 = "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("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\" <someone@microsoft.com>, \"Another\" <another@microsoft.com>")); pMsg->put_From(_bstr_t("\"ThirdPerson\" <thirdperson@microsoft.com>, \"Fourth\" <fourth@microsoft.com>")); pMsg->put_Sender(_bstr_t("\Finally\" <finally@microsoft.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 = "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("c:\somefile.doc") iBp.ContentMediaType="application/msword" Set iBp = .AddAttachment("c:\anotherfile.html") iBp.ContentMediaType="text/html" .Send End With