AutoGenerateTextBody Property

AutoGenerateTextBody Property

The AutoGenerateTextBody property indicates whether the TextBody property of a message should automatically be generated from the contents of the HTMLBody property for a multipart/alternative message.

Syntax

Property AutoGenerateTextBody as Boolean
HRESULT get_AutoGenerateTextBody(VARIANT_BOOL* pVal);
HRESULT put_AutoGenerateTextBody(VARIANT_BOOL Val);

Remarks

If the AutoGenerateTextBody property is set to True (VARIANT_TRUE), the contents of the TextBody property are replaced by the plain text equivalent of the HTMLBody property; that is, the contents with all Hypertext Markup Language (HTML) tags removed.

The following rules apply to the AutoGenerateTextBody property if it is set to True:

  • Setting the HTMLBody property causes the TextBody property to be set immediately.
  • Setting the TextBody property causes the AutoGenerateTextBody property to be set to False.
  • Setting the HTMLBody property causes the MimeFormatted property to be set to True.
  • Setting the MimeFormatted property to False causes the AutoGenerateTextBody property to be set to False.

The default value of the AutoGenerateTextBody property is True (VARIANT_TRUE) on newly created messages and False (VARIANT_FALSE) on previously existing messages.

Example

This code takes advantage of the default settings of the AutoGenerateTextBody and IMessage.MimeFormatted properties to send a message with both plain text and HTML versions of the same text:

' Reference to Microsoft ActiveX Data Objects 2.5 Library
' Reference to Microsoft CDO for Windows 2000 Library
Dim iMsg as New CDO.Message
Dim strHTML as String
strHTML  = "<HTML><h1>Hello There</h1></HTML>"
Set iMsg = New CDO.Message
With iMsg
  .To      = "Somebody@example.com"
  .From    = "another@example.com"
  .Subject = "Sample multipart/alternative message"
  .HTMLBody = strHTML ' .TextBody gets generated automatically
  .Send
End With
#import "c:\program files\common files\system\ado\msado15.dll" no_namespace
#import "c:\\winnt\\system32\\cdosys.dll" no_namespace
#include <cdosysstr.h>
#include <cdosyserr.h>
void main() {
 CoInitialize(NULL);
 {
   IMessagePtr iMsg(__uuidof(Message));
   _bstr_t html   = "<HTML><h1>Hello There</h1></HTML>";
   iMsg->To       = "Somebody@example.com" ;
   iMsg->From     = "another@example.com" ;
   iMsg->Subject  = "Sample multipart/alternative message" ;
   iMsg->HTMLBody = strHTML;
   iMsg->Send();
  }
  CoUninitialize();
}
Dim iMsg
Set iMsg = CreateObject("CDO.Message")
Dim strHTML
strHTML  = "<HTML><h1>Hello There</h1></HTML>"
With iMsg
  .To      = "Somebody@example.com"
  .From    = "another@example.com"
  .Subject = "Sample multipart/alternative message"
  .HTMLBody = strHTML ' .TextBody gets generated automatically
  .Send
End With