I can’t honestly say that I’ve run into a lot of situations where I’ve said to myself, “If only I could send an HTML formatted instant message right now, my problems would go away.” But adding formatting to IMs can definitely help with some specialized communication applications such as bots where you want to distinguish different types of messages, or emphasize certain parts of a conversation. So, to make those nice visual touches easier, and for anyone out there who is in a tight spot by virtue of not knowing how to send an IM with special formatting, I thought I’d write up a quick post on it.

Normally, instant messages from a UCMA application are sent as plain text. This is the easy way to do it, and in code it looks something like this:

The first parameter for this overload of BeginSendInstantMessage needs to be an instance of System.Net.Mime.ContentType; for an HTML message, you can provide the string “text/html” as the parameter for the ContentType constructor. (A normal plain-text IM would have a MIME type of “text/plain”.)

The second parameter is the byte-encoded message body, which you can get by calling Encoding.UTF8.GetBytes with your HTML string.

With code like the above, you get a beautifully formatted instant message like this:

I think this one really communicates the magnitude of the sphinx of quartz we’re talking about here.

That’s about all there is to it. It doesn’t seem to be necessary to wrap everything in <html> and <body> tags, but I usually do it just to feel good about myself. Also, note that you can send links, but they may get blocked depending on the policy settings in your environment.

It’s also possible to send other types of content, such as image/gif or rtf or application/x-ms-ink or multi-part/alternative. Let me know if you find an interesting way to use any of these!