ComposeMessage Method

Compose a new mail message.

Syntax

object.ComposeMessage( From, To [, Cc] [, Bcc] [, Subject] [, Msgtext] [, Msghtml] [, Charset] [, Enctype] )

The ComposeMessage method syntax has the following parts:

Part Description
object An object expression that evaluates to an InternetMail object.
from A string which specifies the sender address.
to A string which specifies one or more recipient addresses.
cc A string which specifies one or more recipient addresses.
bcc A string which specifies one or more recipient addresses.
subject A string which specifies the subject of the message.
msgtext A string which specifies the text of the message.
msghtml A string which specifies optional HTML formatted text.
charset An integer value which specifies the message character set.
enctype An integer value which specifies the message encoding type.

Return Type

Integer

Settings

The settings for Charset are:

Value Constant Description
1 mailCharsetUSASCII The default character set using US-ASCII which defines 7-bit printable characters with values ranging from 20h to 7Eh.
2 mailCharsetISO8859_1 An 8-bit character set for most western European languages such as English, French, Spanish and German. This character set is also commonly referred to as Latin1.
3 mailCharsetISO8859_2 An 8-bit character set for most central and eastern European languages such as Czech, Hungarian, Polish and Romanian. This character set is also commonly referred to as Latin2.
4 mailCharsetISO8859_5 An 8-bit character set for Cyrillic languages such as Russian, Bulgarian and Serbian.
5 mailCharsetISO8859_6 An 8-bit character set for Arabic languages. Note that the application is responsible for displaying text that uses this character set. In particular, any display engine needs to be able to handle the reverse writing direction and analyze the context of the message to correctly combine the glyphs.
6 mailCharsetISO8859_7 An 8-bit character set for the Greek language.
7 mailCharsetISO8859_8 An 8-bit character set for the Hebrew language. Note that similar to Arabic, Hebrew uses a reverse writing direction. An application which displays this character should be capable of processing bi-directional text where a single message may include both right-to-left and left-to-right languages, such as Hebrew and English.
9 mailCharsetISO8859_9 An 8-bit character set for the Turkish language. This character set is also commonly referred to as Latin5.

The settings for Enctype are:

Value Constant Description
1 mailEncoding7Bit Each character is encoded in one or more bytes, with each byte being 8 bits long, with the first bit cleared. This encoding is most commonly used with plain text using the US-ASCII character set, where each character is represented by a single byte in the range of 20h to 7Eh. Most e-mail messages are composed using 7-bit ASCII.
2 mailEncoding8Bit Each character is encoded in one or more bytes, with each byte being 8 bits long and all bits are used. 8-bit encoding may be used with multi-byte character sets, although this encoding type is uncommon in e-mail messages. It is recommended that quoted-printable encoding be used for 8-bit character sets.
4 mailEncodingQuoted Quoted-printable encoding is designed for textual messages where most of the characters are represented by the ASCII character set and is generally human-readable. Non-printable characters or 8-bit characters with the high bit set are encoded as hexadecimal values and represented as 7-bit text. Quoted-printable encoding is typically used for messages which use character sets such as ISO-8859-1, as well as those which use HTML.

Remarks

The ComposeMessage method creates a new mail message, or replaces the current message if one already exists.

The From argument is required and specifies the sender's e-mail address. Only a single address should be specified. After the message has been composed, the From property will be updated with this value.

The To argument is required and specifies one or more recipient e-mail addresses. Multiple e-mail addresses may be specified by separating them with commas. After the message has been composed, the To property will be updated with this value.

The Cc argument is optional and specifies one or more additional recipient addresses that will receive a copy of the message. If this argument is not specified, then no Cc header field will be created for this message. After the message has been composed, the Cc property will be updated with this value.

The Bcc argument is optional and specifies one or more additional recipient addresses that will receive a copy of the message. Unlike the cc argument, these recipients will not be included in the header of the message. If this argument is not specified, then no blind carbon copies of the message will be sent. After the message has been composed, the Bcc property will be updated with this value.

The Subject argument is optional and specifies the subject for the message. If the argument is not specified, then no Subject header field will be created for this message. After the message has been composed, the Subject property will be updated with this value.

The Msgtext argument is optional and specifies the body of the message. Each line of text contained in the string should be terminated with a carriage-return/linefeed (CRLF) pair, which is recognized as the end-of-line. If the argument is not specified, then the message will have an empty body unless the Msghtml argument has been specified.

The Msghtml argument is optional and specifies an alternate HTML formatted message. If the Msgtext argument has been specified, then a multipart message will be created with both plain text and HTML text as the alternative. This allows mail clients to select which message body they wish to display. If the Msgtext argument is not specified or is an empty string, then the message will only contain HTML. Although this is supported, it is not recommended because older mail clients may be unable to display the message correctly.

The Charset and Enctype arguments are optional and specify the character set and encoding type for the message text. The default is for the message to use the standard US-ASCII character set and 7-bit encoding. Note that if an 8-bit character set is selected, the default encoding type will be set to quoted-printable.

This method will return a value of zero if the action was successful. Otherwise, a non-zero error code is returned which indicates the cause of the failure.

Example

The following example composes a message and sends it to the specified recipients:

    Dim nError As Long
    
    nError = InternetMail1.ComposeMessage(comboFrom.Text, _
                                          editTo.Text, _
                                          editCc.Text, _
                                          editBcc.Text, _
                                          editSubject.Text, _
                                          editMessage.Text)
    If nError <> 0 Then
        MessageBox "Unable to compose message", vbExclamation
        Exit Sub
    End If

    nError = InternetMail1.SendMessage()

    If nError <> 0 Then
        MsgBox "Unable to send message", vbExclamation
        Exit Sub
    End If

See Also

Bcc Property, Cc Property, Encoding Property, From Property, MessageText Property, Subject Property, To Property


Copyright © 2008 Catalyst Development Corporation. All rights reserved.