mmahdi
asked on
Using MAPI in VB5
Hi,
I would really appreciate some help on this one.
I am using MAPIMESSAGE and MAPISESSION controls shipped with VB5 to send emails with attachments at runtime.
The problem I have is to allow multiple files to be attached in the same email. I am not quite sure what to do with regards to the message body being large enough to allow for these attachments. I got he program working by sending each file individually, but because of the speed the emails were going, it is not really a solution.
This is sample of my code (for just one attachment):]
MAPIMess.SessionID = MAPISess.SessionID
MAPIMess.MsgIndex = -1
MAPIMess.Compose
MAPIMess.RecipDisplayName = somename
MAPIMess.AddressResolveUI = True
MAPIMess.ResolveName
MAPIMess.MsgReceiptRequest ed = True
MAPIMess.AttachmentIndex = MAPIMess.AttachmentCount
MAPIMess.AttachmentName = "file.txt"
MAPIMess.AttachmentPathNam e = "c:\file.txt"
MAPIMess.AttachmentPositio n = MAPIMess.AttachmentIndex
MAPIMess.AttachmentType = vbAttachTypeData
MAPIMess.MsgSubject = "Testing email"
txtNoteText = String$(MAPIMess.Attachmen tCount, " ") + txtNoteText
MAPIMess.MsgNoteText = txtNoteText
MAPIMess.Send False
Can you please amend this code for more than one atachment file.
Thanks a million!
Baltaz13
I would really appreciate some help on this one.
I am using MAPIMESSAGE and MAPISESSION controls shipped with VB5 to send emails with attachments at runtime.
The problem I have is to allow multiple files to be attached in the same email. I am not quite sure what to do with regards to the message body being large enough to allow for these attachments. I got he program working by sending each file individually, but because of the speed the emails were going, it is not really a solution.
This is sample of my code (for just one attachment):]
MAPIMess.SessionID = MAPISess.SessionID
MAPIMess.MsgIndex = -1
MAPIMess.Compose
MAPIMess.RecipDisplayName = somename
MAPIMess.AddressResolveUI = True
MAPIMess.ResolveName
MAPIMess.MsgReceiptRequest
MAPIMess.AttachmentIndex = MAPIMess.AttachmentCount
MAPIMess.AttachmentName = "file.txt"
MAPIMess.AttachmentPathNam
MAPIMess.AttachmentPositio
MAPIMess.AttachmentType = vbAttachTypeData
MAPIMess.MsgSubject = "Testing email"
txtNoteText = String$(MAPIMess.Attachmen
MAPIMess.MsgNoteText = txtNoteText
MAPIMess.Send False
Can you please amend this code for more than one atachment file.
Thanks a million!
Baltaz13
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Mdougan,
Thanks for the answer! Because it has been a while before I got any reply from somebody, I had to try looking for the answer myself, and used the OLE messaging Object Library functions, which works really well and is also a lot faster than using MAPI32.OCX.
I have to give you the points since you went through the trouble of finding the answer.
Cheers
MMAHDI
Thanks for the answer! Because it has been a while before I got any reply from somebody, I had to try looking for the answer myself, and used the OLE messaging Object Library functions, which works really well and is also a lot faster than using MAPI32.OCX.
I have to give you the points since you went through the trouble of finding the answer.
Cheers
MMAHDI
Bought This Question.
Public Sub SendMail()
Dim sErrors As String
Dim lError As Variant
Dim strMessage As String
Dim Match As String
Dim i As Integer
On Error GoTo SendMailErr
' Either format the text you want to e-mail and put it into the strMessage or
' write a log file out to the hard drive and then do the attachment below
' put Mapi Message into Compose Mode
MapiMess.MsgIndex = -1
i = 1
Match = Dir$(gDirectory & gFileSpec, vbNormal)
Do While Match <> ""
MapiMess.MsgNoteText = MapiMess.MsgNoteText & i & ". "
i = i + 1
Match = Dir()
Loop
MapiMess.MsgNoteText = MapiMess.MsgNoteText & vbCrLf & vbCrLf & " Here are the Status Log Files"
Match = Dir$(gDirectory & gFileSpec, vbNormal)
Do While Match <> ""
' increment Attachment Index
MapiMess.AttachmentIndex = MapiMess.AttachmentCount
' give the name of the file attachment
MapiMess.AttachmentName = Match
' give the full file path of the file attachment
MapiMess.AttachmentPathNam
' tell it what position of the attachment array to attach the file into
MapiMess.AttachmentPositio
' attachment is a data file (vs ole object)
MapiMess.AttachmentType = 0
Match = Dir()
Loop
' E-Mail Subject line
MapiMess.MsgSubject = gFileSpec & " System Status Report"
' Move recipients to the proper fields of the Message
Call CopyNamestoMsgBuffer(False
' Use the session ID of the MapiSess session object
MapiMess.SessionID = MapiSess.SessionID
' Send the mail, but don't resolve the addresses (use the actual directory listing)
MapiMess.Send False
SendMailExit:
Exit Sub
SendMailErr:
sErrors = "SendMail " & Err.Description
If Not IsEmpty(Errors) Then
For Each lError In Errors
sErrors = sErrors & vbCrLf & lError.Description
Next
End If
PrintError sErrors
Resume SendMailExit
End Sub