Skip to content

RTFBody


Overview

The RTFBody property allows you to set and retrieve the Rich Text Format (RTF) content of an email message. When set, it automatically changes the BodyFormat to olFormatRichText.

Syntax

vba
' To set the RTFBody
mailItem.RTFBody = rtfByteArray

' To get the RTFBody
rtfData = mailItem.RTFBody

Return Value

A Byte() value containing the RTFBody of the MailItem.

Example

vba
Sub RTFBodyExample()
    Dim app As New nlsMailer.Application
    Dim mailItem As Object
    Dim rtfContent() As Byte

    ' Create a new mail item
    Set mailItem = app.CreateItem(olMailItem)

    ' Create RTF content using ADODB Stream
    Dim adoStream As Object
    Set adoStream = CreateObject("ADODB.Stream")

    adoStream.Type = 1 ' adTypeBinary
    adoStream.Open

    ' Write RTF content to stream
    Dim rtfString As String
    rtfString = "{\rtf1\ansi\deff0{\\fonttbl{\\f0\\fnil\\fcharset0 Calibri;}}{\*\generator Msftedit 5.41.21.2510;}\viewkind4\uc1\pard\sa200\sl276\slmult1\lang9\\f0\\fs22 This is a Rich Text message with \b bold\b0  and \i italic\i0  formatting.\par}"

    adoStream.Write StrConv(rtfString, vbFromUnicode)
    adoStream.Position = 0

    ' Read RTF content to byte array
    rtfContent = adoStream.Read

    ' Set RTFBody
    mailItem.RTFBody = rtfContent

    mailItem.Display
End Sub