ComposeMessage Method  
 

Compose a new mail message.

Syntax

object.ComposeMessage( From, To, [Cc], [Bcc], [Subject], [MessageText], [MessageHTML], [CharacterSet], [EncodingType] )

Parameters

From
A string that specifies the sender's email address. Only a single address should be used. After the message has been composed, the From property will be updated with this value.
To
A string that specifies one or more recipient email addresses. Multiple email addresses may be specified by separating them with commas. After the message has been composed, the To property will be updated with this value.
Cc
An optional string that 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.
Bcc
An optional string that 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.
Subject
An optional string that 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.
MessageText
An optional string that contains 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 this parameter is not specified, then the message will have an empty body unless the MessageHTML parameter has been specified.
MessageHTML
An optional string that contains an alternate HTML formatted message. If the MessageText parameter 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 MessageText parameter 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.
CharacterSet
An optional integer value which specifies the character set for the message text. If this parameter is omitted, the default is for the message to be composed using the standard UTF-8 character set.
EncodingType
An optional integer value which specifies the default encoding for the message. If this parameter is omitted, the message will use standard 8-bit encoding. This parameter may be one of the following values:
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.
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 is used with UTF-8 and other multi-byte character sets.
3 mailEncodingBinary Binary encoding is essentially the absence of any encoding performed on the message data, and there is no presumption that the data contains textual information. No character set localization or conversion is performed on binary encoded data. This encoding type is not recommended. Instead, binary data should be encoded using the standard base64 algorithm.
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.
5 mailEncodingBase64 Base64 encoding is designed to represent binary data in a form that is not human readable but which can be safely exchanged with servers that only accept 7-bit data. Base64 encoding is typically used with file attachments.
6 mailEncodingUucode Uuencoding and uudecoding is a legacy encoding format that was used before the MIME standard was established. This encoding method has largely been replaced by base64 encoding, although it is still commonly used for binary newsgroup postings on USENET. Although this encoding format is supported, it is not officially part of the MIME standard and its use in email messages is discouraged.

Return Value

A value of zero is returned if the method succeeds. Otherwise, a non-zero error code is returned which indicates the cause of the failure.

Remarks

The ComposeMessage method will replace the current message if one already exists.

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