This one is from a VB6 project and I guess it will not need much if any translation.
Function DoMAPIemail(Subject$, MessageText$, AttPaths$(), Optional Recipient$ = "") As Boolean
'requires a Project reference into MSMAPI32.OCX
Dim i%
Dim OrigDir$, Msg$
Dim MAPISess As MAPISession, MAPIMess As MAPIMessages
Set MAPISess = New MSMAPI.MAPISession
Set MAPIMess = New MSMAPI.MAPIMessages
OrigDir$ = CurDir$
With MAPISess
' XP may need to have a profile set so...
'.LogonUI = False causes problem under XP
.LogonUI = True
.DownLoadMail = False
On Error Resume Next
.SignOn 'changes CurDir$ to MAPI
If Err Then
MsgBox "Error " & Err & " " & Err.Description & " during MAPI Session SignOn"
GoTo exitMapiEmail
End If
On Error GoTo 0
End With
With MAPIMess
.SessionID = MAPISess.SessionID
.Compose
If Len(Recipient$) Then
.RecipAddress = Recipient$
.RecipDisplayName = Recipient$
End If
.MsgSubject = Subject$
.MsgNoteText = MessageText$
For i = 1 To UBound(AttPaths$)
If Len(AttPaths$(i)) Then
.AttachmentIndex = i - 1
.AttachmentPathName = AttPaths$(i)
.AttachmentPosition = i + 1
End If
Next
'by now the mapi controls have set curdir to that of MAPI
ChDrive OrigDir$
ChDir OrigDir$
On Error Resume Next
.Send True 'CurDir$ changes to MAPI again
'Error 32001 returned if user cancels send from Outlook
If Err.Number > 0 And Err.Number <> 32001 Then
Msg$ = "Error " & Err.Number & " " & Err.Description & ", sending email" & vbCrLf
If Err = 32003 Then
Msg$ = Msg$ & vbCrLf & "Please start your email program (e.g. Outlook) manually and try again"
End If
MsgBox Msg$, vbCritical
GoTo exitMapiEmail
End If
On Error GoTo 0
End With
DoEvents
MAPISess.SignOff
DoMAPIemail = True
exitMapiEmail:
Set MAPIMess = Nothing
Set MAPISess = Nothing
On Error GoTo 0
ChDrive OrigDir$
ChDir OrigDir$
End Function