Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Email messages overwritten

Status
Not open for further replies.

Glasgow

IS-IT--Management
Jul 30, 2001
1,669
0
0
GB
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
 
Your attachment index needs to increment. It looks like it is always set to 0 in your code.
 
Thanks for the post kprog.

It is set to zero as there is only ever one attachment per email. I am trying to generate multiple emails (not multiple attachments).
 
In later versions of the control, MAPI will ask the user to confirm any e-mail sent using it (it's an Anti-virus thing) this can be a right pain if you are sending more than one message.
therefore it may be better to look at using a basic STMP control to send your messages.

-----
 
I am prompted to allow access to Outlook for 1,2,5 or 10 minutes - so allowing access for 1 minute should be more than enough to process a few emails. So prompt only appears once but:

a) If EmlSendNow is true and it tries to physically send the messages immediately, it works fine but prompts again for each message - which is a pain but at least it works!
b) If EmlSendNow is false it saves only one message (instead of several) and, just to rub salt in, it saves it in Outlook's InBox (rather than, say, Outbox). It's the one instead of several issue I cannot resolve.

Does the SMTP control to which you refer ship with VB or is it a third party control.
 
Does the SMTP control to which you refer ship with VB or is it a third party control.
It doesn't ship with VB5 you can use the winstock control to write one, you can pick up a sharewhere version (do a google search for "STMP ocx" or something like that)

If you're thinking of writeing one you will need the RFC 821, you can pick it up from
it's the AdHoc mail sending protocal.
I have some code for this but not to hand now sorry, but you can find stuff around if you look hard for it.

-----
 
Thanks for further info kirogl.

I confess I am reluctant to move to a 'more advanced' solution when I can't help thinking that what I'm trying to do should work and I may just be doing something daft!

Someone must surely have had some success with this kind of approach.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top