Simply add a buttons named cmdExit and cmdSend, text boxes named EmailAddress, Subject, MessageText, and a MAPIMessages object (available via Project|Components). Then add the following code. There is a project demonstrating this in the download above.
Function SendMessage(EmailAddress As String, Subject As String, MessageText As String)
On Error GoTo mailerr:
MAPISession1.SignOn
If MAPISession1.SessionID <> 0 Then
With MAPIMessages1
.SessionID = MAPISession1.SessionID
.Compose
.RecipAddress = EmailAddress
.MsgSubject = Subject
.MsgNoteText = MessageText
.Send False
End With
MsgBox "Message Sent.", vbInformation
End If
Exit Function
mailerr:
MsgBox "Error: " & Err.Description, vbCritical
End Function
Private Sub cmdExit_Click()
Unload Me
End Sub
Private Sub cmdSend_Click()
If txtAddress.Text <> vbNullString Then
SendMessage txtAddress.Text, txtSubject.Text, txtMessage.Text
Else
MsgBox "You have not entered the email address to send the message to.", vbInformation
End If
End Sub
Comments