Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Help => Array in Function MAPISendMail

Posted on 1997-12-19
Medium Priority
Last Modified: 2012-05-05
Hello !!

It works fine with just one message attatched or RecipCount <=1 but...
If .FileCount > 1 or .RecipCount > 1 in the Array MAPI generate an error (Nr 2) MAPI_E_FAILURE
Parts of my code:
    'More code before this....
    For X = 0 To Y
    'Other code......
ReDim Preserve MAPIMottagare(X)
    MapiRecip(X).Name = sMottagare$
    MapiRecip(X).Address = s
    MapiRecip(X).Reserved = 0
    MapiRecip(X).RecipClass = 1
    MapiRecip(X).EIDSize = 1000
    MapiRecip(X).EntryID = "" 
    'Send mail w/o dialog
    MAPIMeddelande.RecipCount = Y + 1
    lReturn = MAPISendMail(lSession, hwnd, MAPIMsg, MapiRecip(0), MAPIFiles(0), lDialog, 0)
    'lReturn returns 2 instead of 0 here.
    'More code after this....

Question by:jannea
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2

Accepted Solution

rantanen earned 1600 total points
ID: 1446041

here is simple MAPI application which does not use MAPI controls. Probably you can modify it to your purposes. It works well in my Win95 based network, where I use Windows Messaging as mail provider.

In a module I have following declarations

Option Explicit
Type MapiFile
    Reserved As Long
    Flags As Long
    Position As Long
    PathName As String
    FileName As String
    FileType As String
End Type

Type MAPIMessage
    Reserved As Long
    Subject As String
    NoteText As String
    MessageType As String
    DateReceived As String
    ConversationID As String
    Flags As Long
    RecipCount As Long
    FileCount As Long
End Type

Type MapiRecip
    Reserved As Long
    RecipClass As Long
    Name As String
    Address As String
    EIDSize As Long
    EntryID As String
End Type

Declare Function MAPILogoff Lib "MAPI32.DLL" (ByVal Session&, ByVal UIParam&, ByVal Flags&, ByVal Reserved&) As Long
Declare Function MAPILogon Lib "MAPI32.DLL" (ByVal UIParam&, ByVal User$, ByVal Password$, ByVal Flags&, ByVal Reserved&, Session&) As Long
Declare Function MAPISendMail Lib "MAPI32.DLL" Alias "BMAPISendMail" (ByVal Session&, ByVal UIParam&, Message As MAPIMessage, Recipient() As MapiRecip, File() As MapiFile, ByVal Flags&, ByVal Reserved&) As Long
Declare Function MAPIResolveName Lib "MAPI32.DLL" Alias "BMAPIResolveName" (ByVal Session&, ByVal UIParam&, ByVal UserName$, ByVal Flags&, ByVal Reserved&, Recipient As MapiRecip) As Long

Public Const MAPI_LOGON_UI = &H1
Public Const MAPI_LOGOFF_UI = &H2
Public Const SUCCESS_SUCCESS = 0
Public Const MAPI_TO = 1
Public Const MAPI_DIALOG = &H8

and the under a command button in a form, which has a couple of text boxes where subject and message body are read in. The routine is heavily simplified. You need to add especially error handling there.

Private Sub Command1_Click()
    Dim szMsgID As String
    Dim szMsgType As String
    Dim lhSession As Long
    Dim lResult As Long
    Dim szPathName As String
    Dim szRecipName(2) As String
    Dim lSuccess As Long
    Dim MyMessage As MAPIMessage
    Dim I As Integer
    Dim J As Integer
    szMsgID = ""
    szMsgType = "IPM.Microsoft Mail.Note"
    MyMessage.FileCount = 0&
    MyMessage.Reserved = 0&
    MyMessage.MessageType = szMsgType
    MyMessage.DateReceived = ""
    MyMessage.Flags = 0&
    ReDim mrTemp(0 To 0) As MapiRecip
    ReDim mr(0 To 0) As MapiRecip
    ReDim MF(0 To 0) As MapiFile
    MF(0).Reserved = 0&
    MF(0).Flags = 0&
    MF(0).Position = -1
    MF(0).FileType = ""

    ' **************************************************
    ' Build Message
    ' **************************************************
    MyMessage.Subject = txtSubject
    MyMessage.NoteText = txtMessage
    ' Attachment part removed
    MF(0).PathName = ""
    MF(0).FileName = ""
    MyMessage.FileCount = 0

    ' **************************************************
    ' Build Recipient List
    ' This sample list is hard coded here
    ' **************************************************
    szRecipName(0) = "Lea Rantanen"
    szRecipName(1) = "Mikko Rantanen"
    szRecipName(2) = "Lasse Rantanen"
    ' **************************************************
    ' Login and start the MAPI Session
    ' **************************************************
    lResult = MAPILogon(Form1.hWnd, "", "", 0&, 0&, lhSession)
    If lResult <> SUCCESS_SUCCESS Then
         MsgBox "Error logging in"
         Exit Sub
    End If

    ' **************************************************
    ' Check Addresses Accepting only Valid Ones
    ' **************************************************
    J = 0
    For I = 0 To UBound(szRecipName)
        If Not IsEmpty(szRecipName(I)) Then
            mrTemp(0).Name = szRecipName(I)
            mrTemp(0).RecipClass = MAPI_TO
            lSuccess = MAPIResolveName(lhSession, 0, mrTemp(0).Name, 0, 0, mrTemp(0))
            If lSuccess <> SUCCESS_SUCCESS Then
                MsgBox ("The address for " & mrTemp(0).Name & " is not valid.")
                ReDim Preserve mr(J) As MapiRecip
                mr(J) = mrTemp(0)
                J = J + 1
           End If
        End If
    Next I
    MyMessage.RecipCount = CLng(UBound(mr)) + 1&
    ' **************************************************
    ' Send Mail
    ' **************************************************
    lResult = MAPISendMail(lhSession, Form1.hWnd, MyMessage, mr(), MF(), 0&, 0&)
    ' Check lResult here
    ' **************************************************
    ' Log Off
    ' **************************************************
    lResult = MAPILogoff(lhSession, 0&, 0&, 0&)
    ' Check lResult here
End Sub


Author Comment

ID: 1446042
Hello and thanks !

Sorry I havent respond but I have been bussy.

In the function
lResult = MAPISendMail(lhSession, Form1.hWnd, MyMessage, mr(), MF(), 0&, 0&)
you send mr() instead of mr(0) as I have hear thats the way to do it, I mean sending the first in the array even you got more than one recips or one attatced message. So i did hope that was my problem, but when iI do like this i get the error (ByRef argument type missmatch) so how come it works for you ?

PLS Give me your e-mailadress so I can mail you my function if you can see whats wrong, it still dont works.


Expert Comment

ID: 1446043
My e-mail is Lasse.Rantanen@sci.fi

Author Comment

ID: 1446044
Thanks Lasse

/Janne, Sweden

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses

636 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