I am composing multiple email messages using MAPISession and MAPIMessages objects. I use the .Compose and .Save or .Send methods. On the first call to my routine, I sign on to the session. On subsequent calls I use the same session and do not sign on.
What appears to be happening is that, instead of creating multiple messages, it simply overwrites the same one each time and I end up only with my last message saved. Am I missing something obvious?
Simplified code of the routine to compose the email (called several times to build multiple emails) is as follows:
Private Function GreEmail(OutFile As String, _
OutChan As Integer, _
SpcDat() As SpecialData, _
Optional EmlName As String, _
Optional EmlAddress As String, _
Optional EmlSubject As String, _
Optional EmlText As String, _
Optional EmlSendNow As Boolean, _
Optional EmlCount As Integer)
Dim MpsMail As MAPISession, MpmMsg As MAPIMessages
Set MpsMail = FrmOut.MAPISession
Set MpmMsg = FrmOut.MAPIMessages
If OutFile = "LogOff" Then
MpsMail.SignOff
Exit Function
End If
With MpsMail
If .SessionID = 0 Then
.LogonUI = True
.DownLoadMail = False
.SignOn
End If
End With
If EmlAddress <> "" Then
With MpmMsg
.SessionID = MpsMail.SessionID
.Compose
.RecipAddress = EmlAddress
.RecipDisplayName = EmlAddress
.RecipType = mapToList
.MsgSubject = EmlSubject
.MsgNoteText = " " & vbCrLf & EmlText
.AttachmentIndex = 0
.AttachmentPosition = 0
.AttachmentName = NewName
.AttachmentPathName = NewName
If EmlSendNow Then .Send Else .Save
EmlCount = EmlCount + 1
End With
End If
Exit Function
What appears to be happening is that, instead of creating multiple messages, it simply overwrites the same one each time and I end up only with my last message saved. Am I missing something obvious?
Simplified code of the routine to compose the email (called several times to build multiple emails) is as follows:
Private Function GreEmail(OutFile As String, _
OutChan As Integer, _
SpcDat() As SpecialData, _
Optional EmlName As String, _
Optional EmlAddress As String, _
Optional EmlSubject As String, _
Optional EmlText As String, _
Optional EmlSendNow As Boolean, _
Optional EmlCount As Integer)
Dim MpsMail As MAPISession, MpmMsg As MAPIMessages
Set MpsMail = FrmOut.MAPISession
Set MpmMsg = FrmOut.MAPIMessages
If OutFile = "LogOff" Then
MpsMail.SignOff
Exit Function
End If
With MpsMail
If .SessionID = 0 Then
.LogonUI = True
.DownLoadMail = False
.SignOn
End If
End With
If EmlAddress <> "" Then
With MpmMsg
.SessionID = MpsMail.SessionID
.Compose
.RecipAddress = EmlAddress
.RecipDisplayName = EmlAddress
.RecipType = mapToList
.MsgSubject = EmlSubject
.MsgNoteText = " " & vbCrLf & EmlText
.AttachmentIndex = 0
.AttachmentPosition = 0
.AttachmentName = NewName
.AttachmentPathName = NewName
If EmlSendNow Then .Send Else .Save
EmlCount = EmlCount + 1
End With
End If
Exit Function