Composing Text Messages | ||
To compose a simple text message, you can use the ComposeMessage method and specify the body of the message, along with the other standard header fields. For example, if you had a form with TextBox controls for the sender, recipients, subject and message body you could use code like this: Dim nError As Long nError = MailMessage1.ComposeMessage(editFrom.Text, _ editTo.Text, _ editCc.Text, _ editBcc.Text, _ editSubject.Text, _ editMessage.Text) If nError Then MsgBox "Unable to compose a new message" & vbCrLf & _ MailMessage1.LastErrorString, vbExclamation Exit Sub End If If you have a text file that contains the body of the message that you want to use, then you can create a message without a message body and then read the contents of the file and assign it to the Text property. For example: Dim nError As Long nError = MailMessage1.ComposeMessage(editFrom.Text, _ editTo.Text, _ editCc.Text, _ editBcc.Text, _ editSubject.Text) If nError Then MsgBox "Unable to compose a new message" & vbCrLf & _ MailMessage1.LastErrorString, vbExclamation Exit Sub End If ' Open the file for and assign the contents of the file to the ' Text property which will put it in the body of the message hFile = FreeFile() Open strFileName For Input As hFile MailMessage1.Text = Input(LOF(hFile), hFile) Close hFile To access the complete message, use the Message property, which will return the complete message including the headers and message body. This is most commonly used with the SMTP control to submit the message to a mail server for delivery to the recipients. |
||
Copyright © 2023 Catalyst Development Corporation. All rights reserved. |