Solved

Help => Array in Function MAPISendMail

Posted on 1997-12-19
4
355 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
[X]
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
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

705 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