MAPI Emailer

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

You might also like...

Comments

Alex

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Owning a computer without programming is like having a kitchen and using only the microwave oven” - Charles Petzold