|
Submit the specified message to the mail server for delivery.
Syntax
object.SendMessage( Sender,
Recipients, Message, [Options] )
Parameters
- Sender
- A string argument which specifies the email address of the
person sending the message. This typically corresponds to the
address in the From header of the message, but it is not required
that they be the same.
- Recipients
- A string argument which specifies the email address of the
person or persons to receive the message. Multiple addresses may be
specified by separating each address with a comma. It should be
noted that this protocol is only concerned with the delivery of a
message and not its contents. Header fields in the message are not
parsed to automatically determine the recipients. This argument
should be a concatenation of all recipients, including carbon
copies and blind carbon copies, with each address separated with a
comma.
- Message
- A string argument contains the message to be delivered to the
specified recipients. The message must be text and conform to the
basic structure defined in RFC 822. There must be one or more
headers separated by a blank line, followed by the body of the
message. Each line of text must be terminated by a carriage return
and linefeed character sequence. Note that more complex multipart
MIME messages may also be used, but it is recommended that you use
the Mail Message control to compose them.
- Options
- An optional argument that is reserved for future use. This
argument should be omitted when calling this method.
Return Value
A value of zero is returned if the operation was successful,
otherwise a non-zero error code is returned which indicates the cause
of the failure.
Remarks
The SendMessage method enables an application to send a
formatted email message using the current mail server. This provides
a convenient one-step method of addressing and sending a message, and
is designed to easily integrate with the Mail Message control.
This method will cause the current thread to block until the
message transfer completes, a timeout occurs or the transfer is
canceled. During the transfer, the OnProgress event will fire
periodically, enabling the application to update any user interface
objects such as a progress bar.
Example
The following example demonstrates how to use the
SendMessage method, along with the Mail Message control, to
compose and deliver a message:
' Compose a new message
nError = MailMessage1.ComposeMessage(strFrom, _
strTo, _
strCc, _
strBcc, _
strSubject, _
strMessageText)
If nError > 0 Then
MsgBox MailMessage1.LastErrorString, vbExclamation
Exit Sub
End If
If MailMessage1.Recipients = 0 Then
MsgBox "There are no recipients for this message"
Exit Sub
End If
' Connect to the mail server
nError = SmtpClient1.Connect(strMailServer)
If nError > 0 Then
MsgBox SmtpClient1.LastErrorString, vbExclamation
Exit Sub
End If
' Deliver the message
nError = SmtpClient1.SendMessage(MailMessage1.Sender, MailMessage1.AllRecipients, MailMessage1.Message)
If nError > 0 Then
MsgBox SmtpClient1.LastErrorString, vbExclamation
SmtpClient1.Disconnect
Exit Sub
End If
' Disconnect
SmtpClient1.Disconnect
See Also
AddRecipient Method,
Connect Method,
CreateMessage Method,
Disconnect Method,
OnProgress Event
|
|