Link to home
Start Free TrialLog in
Avatar of sheslop
sheslop

asked on

Using the MAPI Controls

im trying to use the MAPI controls to send emails with attachments. if i ever have more than 1 attachment i get the error "attachment not found". i beleive it has something to do with the attachmentindex proprty of the MAPI control.

code below.

For i = 1 To lstEmailFiles.ListItems.count
       
        With MAPIMessages1
            .SessionID = MAPISession1.SessionID
            .Compose
            .RecipAddress = Trim$(lstEmailFiles.ListItems(i).Text)
            .RecipType = mapToList
            .MsgSubject = txtEmailSubject
            .MsgNoteText = txtEmailMessage
            j = 1
            Do While lstEmailFiles.ListItems(i).SubItems(j) <> ""
                .AttachmentPathName = lblOutputDir & "\" & lstEmailFiles.ListItems(i).SubItems(j)
                .AttachmentType = mapData
                .AttachmentIndex = j - 1
                j = j + 1
            Loop
            .ResolveName
            .Save
            MsgBox (.AttachmentIndex)
            .Send False
        End With
    Next

any help greatly appreciated.
Avatar of iboutchkine
iboutchkine

Can you send several e-mails with 1 attacment each?
ASKER CERTIFIED SOLUTION
Avatar of rpai
rpai

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Richie_Simonetti
Optionally, you could use this excellent/free component:
http://www.freevbcode.com/ShowCode.Asp?ID=109
Are you certain your arrays are 1 based?  most of the time VB arrays are 0 based.

mlmcc
mlmcc, you are right, by default is 0 based until you use
Option base 1 statement.
Richie
I realize that but his comments don't include an indication that he has done that.

If he is using a defined array and still inside it, he could be accessing an undefined or uninitialzed string and then trying to attach the file it is pointing to which of course would not exist.

mlmcc
YOU CAN USE THIS CODE USING MAPISESSION AND MAPIMESSAGE

Private Sub CmdSend_Click()

MAPISession1.SignOn
For i = 1 To 4
MAPIMessages1.SessionID = MAPISession1.SessionID
MAPIMessages1.MsgIndex = -1
MAPIMessages1.MsgNoteText = "Hello Have a nice Day"
MAPIMessages1.MsgSubject = "Hai"
MAPIMessages1.RecipDisplayName = "jinijosek@rediffmail.com"
MAPIMessages1.AttachmentPathName = "c:\test.txt"
MAPIMessages1.Send (0)
Next i
MAPISession1.SignOff

END SUB

JINI
Avatar of sheslop

ASKER

example code was exactly what i required.