Solved

Help => Array in Function MAPISendMail

Posted on 1997-12-19
4
312 Views
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 = ""
    DoEvents
    Next
    '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....

/Janne
0
Comment
Question by:jannea
  • 2
  • 2
4 Comments
 
LVL 4

Accepted Solution

by:
rantanen earned 400 total points
ID: 1446041
Janne,

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.")
            Else
                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

0
 
LVL 1

Author Comment

by:jannea
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.

/Janne
0
 
LVL 4

Expert Comment

by:rantanen
ID: 1446043
My e-mail is Lasse.Rantanen@sci.fi
0
 
LVL 1

Author Comment

by:jannea
ID: 1446044
Thanks Lasse

/Janne, Sweden
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now