This documentation is archived and is not being maintained.

IUccInstantMessagingSession.SendMessage Method

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

Sends an instant message to all participants in the session.

Namespace: Microsoft.Office.Interop.UccApi
Assembly: Microsoft.Office.Interop.UccApi (in

void SendMessage (
	string bstrContentType,
	string bstrMessage,
	UccOperationContext pOperationContext
void SendMessage (
	String bstrContentType, 
	String bstrMessage, 
	UccOperationContext pOperationContext
function SendMessage (
	bstrContentType : String, 
	bstrMessage : String, 
	pOperationContext : UccOperationContext



A value of the BSTR (string, for a .NET application) type. For text messages the value could be "text/plain", "text/html" or "text/enriched". The bstrContentType values are restricted to known MIME text content types.


A value of the BSTR (string, for a .NET application) type. This represents the text message to be sent.


A value of the IUccOperationContext* (UccOperationContext, for a .NET application) type. The default value is NULL. This is the optional application-defined operation context useful for facilitating the asynchronous event handling.

SendMessage should specify text messages are sent with the "text/plain", "text/html" or "text/enriched" MIME content types. Plain text does not provide for or allow formatting commands, font attribute specifications, processing instructions, interpretation directives, or content markup. Plain text is seen simply as a linear sequence of characters, possibly interrupted by line breaks or page breaks. Line breaks in text sent via SendMessage must be represented as a CRLF sequence.

When sending text as "text/html" or "text/enriched", it is the responsibility of the sending and receiving clients to ensure html or rich text mark-up tags are valid.

The intent of ContentType is to allow a client to parse received text properly. The string value of ContentType is not limited to standard MIME types. A custom client can create "custom" types with the understanding that remote custom clients recognize the custom type and can parse accordingly.

To maintain interoperability with a remote Office Communicator client session participant, the local client must send text with the "text/plain" MIME content type.

Win32 COM/C++ Syntax

HRESULT SendMessage
   BSTR bstrContentType,
   BSTR bstrMessage,
   IUccOperationContext* pOperationContext
In a Win32 application, the return value of a method or property is always an HRESULT value indicating the status of the call to the interface member. Any result of the operation is returned as a parameter marked with the [out, retval] attribute. In contrast, in a .NET application the HRESULT value indicating an error condition is returned as a COM exception and the [out, retval] parameter becomes the return value. For the UCC API-defined HRESULT values, see Trace and Handle Errors in Unified Communications Client API.

The following example accepts an instance of IUccInstantMessagingSession, a string containing the message to be sent, and a string describing the MIME content type of the sent message. The client that receives the sent message can read the ContentType property of the received message to determine how to display the received message.

/// <summary>
/// sends text message in format specified
/// </summary>
/// <param name="pIMsession">IM session with which the message is to be sent</param>
/// <param name="pMessageToSend">string message to send</param>
/// <param name="pMIMEContentType">string content type</param>
private void SendMessage(
    IUccInstantMessagingSession pIMsession,
    string pMessageToSend, 
    string pMIMEContentType)
    if (pMessageToSend.Length > 0 && pMIMEContentType.Length > 0)
        UccOperationContext opContext = new UccOperationContext();
        UccContext ctx = new UccContext();
        ctx.AddNamedProperty("MIMEContentType", pMIMEContentType);
        opContext.Initialize(0, ctx);

            switch (pMIMEContentType)
                case "Plain text":
                    pIMsession.SendMessage("text/plain", pMessageToSend, opContext);
                case "Rich Text":
                    pIMsession.SendMessage("text/enriched", pMessageToSend, opContext);
                case "HTML Markup":
                    pIMsession.SendMessage("text/html", pMessageToSend, opContext);
                    pIMsession.SendMessage("text/plain", pMessageToSend, opContext);
        catch (COMException ce)
            Console.WriteLine("COM exception " + ce.ErrorCode);

All public static (Shared in Visual Basic) members of this type are thread-safe. Instance members are not guaranteed to be thread-safe.

Development Platforms

Windows XP Professional with Service Pack 2 (SP2), Windows Server 2000 with Service Pack 4, Windows Server 2003, Windows Vista Ultimate Edition, Windows Vista Business Edition, Windows Vista Enterprise Edition

Target Platforms