Just paste this code into any class and change the name of the class to cMAPI.
'----------------------------------------------------------------------
'
' Class Name: cMAPI
' Written By: C&D Programming Corp.
' Create Date: 1/12/98
' Copyright: Copyright 1997-98 by C&D Programming Corp. Source
' code may not be reproduced except for use in a
' compiled executable. All rights reserved. If
' you would like to reprint any or all of this
' code please email us at info@codeoftheweek.com
'
'
'----------------------------------------------------------------------
Option Explicit
'
' To send a message you do something like this:
'
' Set MAPI.MAPISessionControl = MAPISess1
' Set MAPI.MAPIMessageControl = MAPIMsg1
' MAPI.ComposeMessage "Subject", "Message"
' MAPI.AddRecipient "joe@codeoftheweek.com", RecipTypeTo
' MAPI.SendMessage
'
Public Enum eRecipType
RecipTypeTo = 1
RecipTypeCC = 2
End Enum
Public MAPIMsg As MAPIMessages
Public MAPISess As MAPISession
Public Property Set MAPISessionControl(ctl As Control)
Set MAPISess = ctl
MAPISess.SignOn
End Property
Public Property Set MAPIMessageControl(ctl As Control)
Set MAPIMsg = ctl
MAPIMsg.SessionID = MAPISess.SessionID
End Property
Public Sub AddRecipient(sName As String, eType As eRecipType)
MAPIMsg.RecipIndex = MAPIMsg.RecipCount
MAPIMsg.RecipType = eType
MAPIMsg.RecipDisplayName = sName
MAPIMsg.ResolveName
End Sub
Public Sub SendMessage()
MAPIMsg.Send False
End Sub
Public Sub ComposeMessage(sSubject As String, sMsg As String)
MAPIMsg.Compose
MAPIMsg.MsgSubject = sSubject
MAPIMsg.MsgNoteText = sMsg
End Sub
Private Sub Class_Terminate()
If Not MAPISess Is Nothing Then
MAPISess.SignOff
End If
End Sub