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.co unt
With MAPIMessages1
.SessionID = MAPISession1.SessionID
.Compose
.RecipAddress = Trim$(lstEmailFiles.ListIt ems(i).Tex t)
.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.
code below.
For i = 1 To lstEmailFiles.ListItems.co
With MAPIMessages1
.SessionID = MAPISession1.SessionID
.Compose
.RecipAddress = Trim$(lstEmailFiles.ListIt
.RecipType = mapToList
.MsgSubject = txtEmailSubject
.MsgNoteText = txtEmailMessage
j = 1
Do While lstEmailFiles.ListItems(i)
.AttachmentPathName = lblOutputDir & "\" & lstEmailFiles.ListItems(i)
.AttachmentType = mapData
.AttachmentIndex = j - 1
j = j + 1
Loop
.ResolveName
.Save
MsgBox (.AttachmentIndex)
.Send False
End With
Next
any help greatly appreciated.
Can you send several e-mails with 1 attacment each?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Optionally, you could use this excellent/free component:
http://www.freevbcode.com/ShowCode.Asp?ID=109
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
mlmcc, you are right, by default is 0 based until you use
Option base 1 statement.
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
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.RecipDisplay Name = "jinijosek@rediffmail.com"
MAPIMessages1.AttachmentPa thName = "c:\test.txt"
MAPIMessages1.Send (0)
Next i
MAPISession1.SignOff
END SUB
JINI
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.RecipDisplay
MAPIMessages1.AttachmentPa
MAPIMessages1.Send (0)
Next i
MAPISession1.SignOff
END SUB
JINI
ASKER
example code was exactly what i required.