Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Using MAPI in VB5

Posted on 1998-11-25
4
Medium Priority
?
349 Views
Last Modified: 2008-02-26
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.MsgReceiptRequested = True

MAPIMess.AttachmentIndex = MAPIMess.AttachmentCount
MAPIMess.AttachmentName = "file.txt"
MAPIMess.AttachmentPathName = "c:\file.txt"
MAPIMess.AttachmentPosition = MAPIMess.AttachmentIndex
MAPIMess.AttachmentType = vbAttachTypeData

MAPIMess.MsgSubject = "Testing email"
txtNoteText = String$(MAPIMess.AttachmentCount, " ") + txtNoteText
MAPIMess.MsgNoteText = txtNoteText
MAPIMess.Send False

Can you please amend this code for more than one atachment file.

Thanks a million!
Baltaz13
0
Comment
Question by:mmahdi
  • 2
4 Comments
 
LVL 18

Accepted Solution

by:
mdougan earned 300 total points
ID: 1446834
I'm doing this from memory only, but try repeating the block that begins with the line
MAPIMess.AttachmentIndex = MAPIMess.AttachmentCount

Once you've done the first block, the AttachmentCount should increment automatically, so when you do the second block (except you'll want to attach a different file in the second block), the AttachmentIndex will be one more.  This is easy to step through and verify.  I have some code to verify that this is the solution, but I'll have to post it at a later date.

MD
0
 
LVL 18

Expert Comment

by:mdougan
ID: 1446835
Here is the procedure that I use to attach multiple files to a single e-mail then send it out.  I haven't included all of the code for the setting of the Send To list etc. but I think this is what you'd asked for.


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.AttachmentPathName = gDirectory & Match

' tell it what position of the attachment array to attach the file into
        MapiMess.AttachmentPosition = (MapiMess.AttachmentCount * 2) + MapiMess.AttachmentIndex
   
' 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

0
 
LVL 1

Author Comment

by:mmahdi
ID: 1446836
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
0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1446837
Bought This Question.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

824 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question