|
|
To compose and send a text e-mail message to one or more
recipients, you only need to use two methods, ComposeMessage
and SendMessage. Here is an example of how they could be
used to send a message using the information entered by the user on
a form:
Private Sub cmdSend_Click()
Dim nError As Long
cmdSend.Enabled = False
nError = InternetMail1.ComposeMessage(editFrom.Text, _
editTo.Text, _
editCc.Text, _
editBcc.Text, _
editSubject.Text, _
editMessage.Text)
If nError Then
MsgBox "Unable to compose a new message" & vbCrLf & _
InternetMail1.LastErrorString, vbExclamation
Exit Sub
End If
nError = InternetMail1.SendMessage()
If nError Then
MsgBox "Unable to send the message" & vbCrLf & _
InternetMail1.LastErrorString, vbExclamation
Exit Sub
End If
cmdSend.Enabled = True
End Sub
The ComposeMessage method creates a new message and has
the following arguments:
| Property |
Description |
| From |
A string value which specifies the
e-mail address of the person sending the message. This argument is
required. |
| To |
A string value which specifies one
or more e-mail addresses of those who will receive the message.
Multiple addresses may be separated by a comma (such as
"john@company.com, jane@company.com"). This argument is
required. |
| Cc |
An optional string value which
specifies recipients who should receive a copy of the message.
Multiple recipients may be separated by a comma and the addresses
are included in the header of the message. |
| Bcc |
An optional string value which
specifies recipients who should receive a copy of the message,
however, these addresses are not included in the header of the
message. Multiple recipients may be separated by a comma. |
| Subject |
An optional string value which
specifies the subject of the message. If the argument is not
specified then the message is created without a subject. |
| MessageText |
An optional string value which
specifies the body of the message. If the argument is not
specified, then the message is created without a body. |
| MessageHTML |
An optional string value which
specifies an HTML version of the message. If this argument is
provided along with the MessageText argument, then a
multipart message is created which contains both plain text and
HTML versions of the message. If the MessageText argument
has not been specified, then only an HTML message is created. If
this argument is omitted, then the message is sent with only a
plain text body. |
| CharacterSet |
An optional integer value which
specifies a character set to use when composing the message. This
typically only needs to be set for languages which use extended
characters. For more information on the available character sets,
consult the technical reference. |
| EncodingType |
An optional integer value which
specifies an encoding type to be used with the character set that
was selected. For more information about the encoding types
available, consult the technical reference. |
The SendMessage method has four optional arguments:
| Property |
Description |
| Sender |
An optional string value which
specifies the sender of the message. If this argument is provided,
then the message will be identified as being sent from this
address. If the argument is omitted, then the value of the
From property is used. Note that specifying a different
sender address does not change the contents of the message. |
| Recipient |
An optional string value which
specifies one or more recipient e-mail addresses. Multiple
addresses may be separated by a comma. If this argument is
provided, then the message will be delivered only to those
recipients, regardless of the addresses listed in the message
itself. If the argument is omitted, then the addresses listed in
the To, Cc and Bcc properties are used. Note
that specifying a different recipient does not change the contents
of the message. |
| Message |
An optional string value which
specifies a complete, formatted e-mail message including all
headers and the body. If this argument is provided, then the
message is used instead of the current message; otherwise the
current message will be sent. If this argument has been specified,
but the Sender or Recipient arguments have been
omitted, the message is parsed and the values of the From, To and
Cc header fields are used as appropriate. It is expected that this
string contain a complete, correctly formatted message which
conforms to the RFC 822 and MIME e-mail standards. |
| Options |
A long integer value which
specifies one or more options to be used when sending the message.
If this argument is omitted, the value of the Options
property is used. The most common option that is used is
mailOptionNotify which enables delivery status notification
(DSN) if it is supported by the server. This tells the server to
return a message back to the sender indicating the message has been
delivered or if there were any errors encountered during delivery.
Note that if the server does not support DSN, this option is
ignored and will not affect the delivery of the message
itself. |
In most cases, the optional arguments to the SendMessage
method will not be used. They are primarily provided for advanced
applications which need to control the sender, recipient or message
contents that are being sent to the SMTP server.
|
|