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
' Updated: 4/99
' Copyright: Copyright 1997-99 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
'
' Signing onto this way will force a synchronization of messages with the
' server in you are running in remote mode. You can modify the DownloadMail
' property to modify this behavior.
'
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
Public Sub AddAttachment(sAttachmentName As String, sFilename As String)
If MAPIMsg.AttachmentCount = 0 Then
MAPIMsg.AttachmentIndex = 0
Else
MAPIMsg.AttachmentIndex = MAPIMsg.AttachmentCount
End If
' Other Attachment Type available are:
' mapData 0 The attachment is a data file.
' mapEOLE 1 The attachment is an embedded OLE object.
' mapSOLE 2 The attachment is a static OLE object.
MAPIMsg.AttachmentType = mapData
MAPIMsg.AttachmentName = sAttachmentName
MAPIMsg.AttachmentPathName = sFilename
' Make room for the attachment.
MAPIMsg.MsgNoteText = MAPIMsg.MsgNoteText & " "
MAPIMsg.AttachmentPosition = Len(MAPIMsg.MsgNoteText) - 1
End Sub