Dim MessageOut As MAPIMessage
Dim Recipients(0) As MapiRecip
Dim Attachments(0) As MapiFile
Dim lResult As Long
Dim lhSession As Long
'set message main properties
With MessageOut
.Reserved = 0
.NoteText = "this is the message body" & vbCrLf
.FileCount = 0 'no attachments
.RecipCount = 1 'only 1 recipient
.Subject = "this is a test message" & vbCrLf
.MessageType = "IPM.Microsoft Mail.Note"
.Flags = 0
End With
'set recipients
With Recipients(0)
.RecipClass = MAPI_TO 'To
.Name = "Ho kennet"
End With
'set attachments
'not required because message.filecount = 0
rc& = MAPILogon(frmSharePass.hWnd, "", "", MAPI_LOGON_UI, 0&, lhSession)
lResult = MAPISendMail(lhSession, frmSharePass.hWnd, MessageOut,
Recipients, Attachments, 8, 0&)
MsgBox Hex(lResult) ' I got &H80004005 here
rc& = MAPILogoff(lhSession&, 0&, 0&, 0&)
'**************************************************************************
'
'
'
' Visual Basic declaration for the MAPI functions.
'
' This file can be loaded into the global module.
'
'
'
'
'**************************************************************************
'
'***************************************************
' MAPI Message holds information about a message
'***************************************************
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
'************************************************
' MAPIRecip holds information about a message
' originator or recipient
'************************************************
Type MapiRecip
Reserved As Long
RecipClass As Long
Name As String
Address As String
EIDSize As Long
EntryID As String
End Type
'******************************************************
' MapiFile holds information about file attachments
'******************************************************
Type MapiFile
Reserved As Long
Flags As Long
Position As Long
PathName As String
FileName As String
FileType As String
End Type
'***************************
' FUNCTION Declarations
'***************************
Declare Function MAPILogon Lib "MAPI32.DLL" (ByVal UIParam&, ByVal
User$, ByVal Password$, ByVal Flags&, ByVal Reserved&, Session&) As Long
Declare Function MAPILogoff Lib "MAPI32.DLL" (ByVal Session&, ByVal
UIParam&, ByVal Flags&, ByVal Reserved&) As Long
Declare Function BMAPIReadMail Lib "MAPI32.DLL" (lMsg&, nRecipients&,
nFiles&, ByVal Session&, ByVal UIParam&, MessageID$, ByVal Flag&, ByVal
Reserved&) As Long
Declare Function BMAPIGetReadMail Lib "MAPI32.DLL" (ByVal lMsg&, Message
As MAPIMessage, Recip() As MapiRecip, File() As MapiFile, Originator As
MapiRecip) As Long
Declare Function MAPIFindNext Lib "MAPI32.DLL" Alias "BMAPIFindNext"
(ByVal Session&, ByVal UIParam&, MsgType$, SeedMsgID$, ByVal Flag&, ByVal
Reserved&, MsgID$) As Long
Declare Function MAPISendDocuments Lib "MAPI32.DLL" (ByVal UIParam&,
ByVal DelimStr$, ByVal FilePaths$, ByVal FileNames$, ByVal Reserved&) As
Long
Declare Function MAPIDeleteMail Lib "MAPI32.DLL" (ByVal Session&, ByVal
UIParam&, ByVal MsgID$, ByVal Flags&, ByVal Reserved&) 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 MAPISaveMail Lib "MAPI32.DLL" Alias "BMAPISaveMail"
(ByVal Session&, ByVal UIParam&, Message As MAPIMessage, Recipient() As
MapiRecip, File() As MapiFile, ByVal Flags&, ByVal Reserved&, MsgID$) As
Long
Declare Function BMAPIAddress Lib "MAPI32.DLL" (lInfo&, ByVal Session&,
ByVal UIParam&, Caption$, ByVal nEditFields&, Label$, nRecipients&, Recip()
As MapiRecip, ByVal Flags&, ByVal Reserved&) As Long
Declare Function BMAPIGetAddress Lib "MAPI32.DLL" (ByVal lInfo&, ByVal
nRecipients&, Recipients() As MapiRecip) As Long
Declare Function MAPIDetails Lib "MAPI32.DLL" Alias "BMAPIDetails"
(ByVal Session&, ByVal UIParam&, Recipient As MapiRecip, 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
'**************************
' CONSTANT Declarations
'**************************
'
Global Const SUCCESS_SUCCESS = 0
Global Const MAPI_USER_ABORT = 1
Global Const MAPI_E_USER_ABORT = MAPI_USER_ABORT
Global Const MAPI_E_FAILURE = 2
Global Const MAPI_E_LOGIN_FAILURE = 3
Global Const MAPI_E_LOGON_FAILURE = MAPI_E_LOGIN_FAILURE
Global Const MAPI_E_DISK_FULL = 4
Global Const MAPI_E_INSUFFICIENT_MEMORY = 5
Global Const MAPI_E_BLK_TOO_SMALL = 6
Global Const MAPI_E_TOO_MANY_SESSIONS = 8
Global Const MAPI_E_TOO_MANY_FILES = 9
Global Const MAPI_E_TOO_MANY_RECIPIENTS = 10
Global Const MAPI_E_ATTACHMENT_NOT_FOUND = 11
Global Const MAPI_E_ATTACHMENT_OPEN_FAILURE = 12
Global Const MAPI_E_ATTACHMENT_WRITE_FAILURE = 13
Global Const MAPI_E_UNKNOWN_RECIPIENT = 14
Global Const MAPI_E_BAD_RECIPTYPE = 15
Global Const MAPI_E_NO_MESSAGES = 16
Global Const MAPI_E_INVALID_MESSAGE = 17
Global Const MAPI_E_TEXT_TOO_LARGE = 18
Global Const MAPI_E_INVALID_SESSION = 19
Global Const MAPI_E_TYPE_NOT_SUPPORTED = 20
Global Const MAPI_E_AMBIGUOUS_RECIPIENT = 21
Global Const MAPI_E_AMBIG_RECIP = MAPI_E_AMBIGUOUS_RECIPIENT
Global Const MAPI_E_MESSAGE_IN_USE = 22
Global Const MAPI_E_NETWORK_FAILURE = 23
Global Const MAPI_E_INVALID_EDITFIELDS = 24
Global Const MAPI_E_INVALID_RECIPS = 25
Global Const MAPI_E_NOT_SUPPORTED = 26
Global Const MAPI_ORIG = 0
Global Const MAPI_TO = 1
Global Const MAPI_CC = 2
Global Const MAPI_BCC = 3
'***********************
' FLAG Declarations
'***********************
'* MAPILogon() flags *
Global Const MAPI_LOGON_UI = &H1
Global Const MAPI_NEW_SESSION = &H2
Global Const MAPI_FORCE_DOWNLOAD = &H1000
'* MAPILogoff() flags *
Global Const MAPI_LOGOFF_SHARED = &H1
Global Const MAPI_LOGOFF_UI = &H2
'* MAPISendMail() flags *
Global Const MAPI_DIALOG = &H8
'* MAPIFindNext() flags *
Global Const MAPI_UNREAD_ONLY = &H20
Global Const MAPI_GUARANTEE_FIFO = &H100
'* MAPIReadMail() flags *
Global Const MAPI_ENVELOPE_ONLY = &H40
Global Const MAPI_PEEK = &H80
Global Const MAPI_BODY_AS_FILE = &H200
Global Const MAPI_SUPPRESS_ATTACH = &H800
'* MAPIDetails() flags *
Global Const MAPI_AB_NOMODIFY = &H400
'* Attachment flags *
Global Const MAPI_OLE = &H1
Global Const MAPI_OLE_STATIC = &H2
'* MapiMessage flags *
Global Const MAPI_UNREAD = &H1
Global Const MAPI_RECEIPT_REQUESTED = &H2
Global Const MAPI_SENT = &H4
Function CopyFiles(MfIn As MapiFile, MfOut As MapiFile) As Long
MfOut.FileName = MfIn.FileName
MfOut.PathName = MfIn.PathName
MfOut.Reserved = MfIn.Reserved
MfOut.Flags = MfIn.Flags
MfOut.Position = MfIn.Position
MfOut.FileType = MfIn.FileType
CopyFiles = 1&
End Function
Function CopyRecipient(MrIn As MapiRecip, MrOut As MapiRecip) As Long
MrOut.Name = MrIn.Name
MrOut.Address = MrIn.Address
MrOut.EIDSize = MrIn.EIDSize
MrOut.EntryID = MrIn.EntryID
MrOut.Reserved = MrIn.Reserved
MrOut.RecipClass = MrIn.RecipClass
CopyRecipient = 1&
End Function
Function MAPIAddress(Session As Long, UIParam As Long, Caption As
String, nEditFields As Long, Label As String, nRecipients As Long, Recips()
As MapiRecip, Flags As Long, Reserved As Long) As Long
Dim Info&
Dim rc&
Dim nRecips As Long
ReDim Rec(0 To nRecipients) As MapiRecip
' Use local variable since BMAPIAddress changes the passed value
nRecips = nRecipients
'*****************************************************
' Copy input recipient structure into local
' recipient structure used as input to BMAPIAddress
'*****************************************************
For i = 0 To nRecipients - 1
Ignore& = CopyRecipient(Recips(i), Rec(i))
Next i
rc& = BMAPIAddress(Info&, Session&, UIParam&, Caption$,
nEditFields&, Label$, nRecips&, Rec(), Flags, 0&)
If (rc& = SUCCESS_SUCCESS) Then
'**************************************************
' New recipients are now in the memory referenced
' by Info (HANDLE). nRecipients is the number of
' new recipients.
'**************************************************
nRecipients = nRecips ' Copy back to parameter
If (nRecipients > 0) Then
ReDim Rec(0 To nRecipients - 1) As MapiRecip
rc& = BMAPIGetAddress(Info&, nRecipients&, Rec())
'*********************************************
' Copy local recipient structure to
' recipient structure passed as procedure
' parameter. This is necessary because
' VB doesn't seem to work properly when
' the procedure parameter gets passed
' directory to the BMAPI.DLL Address routine
'*********************************************
ReDim Recips(0 To nRecipients - 1) As MapiRecip
For i = 0 To nRecipients - 1
Ignore& = CopyRecipient(Rec(i), Recips(i))
Next i
End If
End If
MAPIAddress = rc&
End Function
Function MAPIReadMail(Session As Long, UIParam As Long, MessageID As
String, Flags As Long, Reserved As Long, Message As MAPIMessage, Orig As
MapiRecip, RecipsOut() As MapiRecip, FilesOut() As MapiFile) As Long
Dim Info&
Dim nFiles&, nRecips&
rc& = BMAPIReadMail(Info&, nRecips, nFiles, Session, 0, MessageID,
Flags, Reserved)
If (rc& = SUCCESS_SUCCESS) Then
'Message is now read into the handles array. We have to redim the
'arrays and read the information in.
If (nRecips = 0) Then nRecips = 1
If (nFiles = 0) Then nFiles = 1
ReDim Recips(0 To nRecips - 1) As MapiRecip
ReDim Files(0 To nFiles - 1) As MapiFile
rc& = BMAPIGetReadMail(Info&, Message, Recips(), Files(), Orig)
'*******************************************
' Copy Recipient and File structures from
' Local structures to those passed as
' parameters
'*******************************************
ReDim FilesOut(0 To nFiles - 1) As MapiFile
ReDim RecipsOut(0 To nRecips - 1) As MapiRecip
For i = 0 To nRecips - 1
Ignore& = CopyRecipient(Recips(i), RecipsOut(i))
Next i
For i = 0 To nFiles - 1
Ignore& = CopyFiles(Files(i), FilesOut(i))
Next i
End If
MAPIReadMail = rc&
End Function
I hope this helps!
Fauzia Awan
Microsoft Developer Support - Messaging
This posting is provided "AS IS" with no warranties, and confers no rights.
© 2001 Microsoft Corporation. All rights reserved.
I've download the Mapivb32.bas from MS before and it didn't work. I
found that must declare Types and Functions in C type(not VB). It works
correctly. But I don't know why?
Bonnie
Fauzia Awan [MS] <fau...@online.microsoft.com> wrote in message
news:huHTxD1rBHA.2436@cpmsftngxa07...
> ?2001 Microsoft Corporation. All rights reserved.
>
>
>
Fauzia Awan [MS] <fau...@online.microsoft.com> wrote in message
news:huHTxD1rBHA.2436@cpmsftngxa07...
> ?2001 Microsoft Corporation. All rights reserved.
>
>
>
Fauzia Awan
Microsoft Developer Support - Messaging
This posting is provided "AS IS" with no warranties, and confers no rights.
© 2001 Microsoft Corporation. All rights reserved.
Public Type MAPIMessageC
ulReserved As Long
lpszSubject As String
lpszNoteText As String
lpszMessageType As String
lpszDateReceived As String
lpszConversationID As String
flFlags As Long
lpOriginator As MapiRecipDesc
nRecipCount As Long
lpRecips As MapiRecipDesc
nFileCount As Long
lpFiles As MapiFileDesc
End Type
Public Type MapiRecipDesc
ulReserved As Long
ulRecipClass As Long
lpszName As String
lpszAddress As String
ulEIDSize As Long
lpEntryID As String
End Type
Public Type MapiFileDesc
Reserved As Long
Flags As Long
Position As Long
PathName As String
FileName As String
FileType As String
End Type
Declare Function MAPISendMail Lib "MAPI32.DLL" (ByVal Session&, _
ByVal UIParam&, _
Message As MAPIMessageC, _
ByVal Flags&, _
ByVal Reserved&) As Long
It seems that all functions with prefix "B"
(BMAPISendMail,BMAPIResolveName...) not work in my MAPI32.dll. I don't know
if something wrong with this dll because I installed a software named
"FoxMail" before. Help me please.
Fauzia Awan [MS] <fau...@online.microsoft.com> wrote in message
news:mGYLBI$rBHA.2488@cpmsftngxa07...
> HI,
> I donot understand what you mean by "I
> found that must declare Types and Functions in C type(not VB). "
> Mapivb32.bas uses BMAPI which can have "C types" but in Basic.
>
> Fauzia Awan
> Microsoft Developer Support - Messaging
>
> This posting is provided "AS IS" with no warranties, and confers no
rights.
> ?2001 Microsoft Corporation. All rights reserved.
>
Fauzia Awan
Microsoft Developer Support - Messaging
This posting is provided "AS IS" with no warranties, and confers no rights.
© 2001 Microsoft Corporation. All rights reserved.
other information:
Service Pack 3
1.0
Microsoft Exchange
Fauzia Awan [MS] <fau...@online.microsoft.com> wrote in message
news:gJhvP2LsBHA.700@cpmsftngxa08...
> Hi Bonnie,
> I am not aware how FoxMail works. It might have its own MAPI subsystem
> which might not have BMAPI implementation in it. Can you tell us the
size,
> version, dates of mapi32.dll file on your system? We would be able make
out
> something from thereon.
>
>
> Fauzia Awan
> Microsoft Developer Support - Messaging
>
> This posting is provided "AS IS" with no warranties, and confers no
rights.
> ?2001 Microsoft Corporation. All rights reserved.
>
Fauzia Awan
Microsoft Developer Support - Messaging
This posting is provided "AS IS" with no warranties, and confers no rights.
© 2001 Microsoft Corporation. All rights reserved.
Could you tell me what's the difference between type C and type VB
functions? Can I send mail in every PC that has the mapi32.dll?
Fauzia Awan [MS] <fau...@online.microsoft.com> wrote in message
news:yHZcNuysBHA.1516@cpmsftngxa08...
> HI Bonnie,
> mapi32.dll looks fine. Nothing wrong there. I cant see any reason why
BMAPi
> functions wont work on your machine. Try setting outlook as your default
> email client. Also paste the code I sent you in my first email and save it
> as .bas file and include it in your VB project and try running it again.
>
>
> Fauzia Awan
> Microsoft Developer Support - Messaging
>
> This posting is provided "AS IS" with no warranties, and confers no
rights.
> ?2001 Microsoft Corporation. All rights reserved.
>
Fauzia Awan
Microsoft Developer Support - Messaging
This posting is provided "AS IS" with no warranties, and confers no rights.
© 2001 Microsoft Corporation. All rights reserved.
Fauzia Awan [MS] <fau...@online.microsoft.com> wrote in message
news:9mRe4EctBHA.2128@cpmsftngxa08...
> Hi Bonnie,
> Can you please tell me if your default mail client is outlook express?
>
> Fauzia Awan
> Microsoft Developer Support - Messaging
>
> This posting is provided "AS IS" with no warranties, and confers no
rights.
> ?2001 Microsoft Corporation. All rights reserved.
>
"CAUSE
=====
VB programs using Simple MAPI usually use declare statements importing the
BMAPI
functions. When Outlook Express is the default mail client, the MAPI Stub
Library cannot route these calls to Outlook Express, so instead they fail
and
the PreFirstRun message is displayed. See More Information for an in-depth
explanation of the issue.
RESOLUTION
==========
- The best resolution is to not use declare statements based on the BMAPI
functions. Since VB can't call the non-BMAPI functions without resorting
to
tricks to manipulate the required structures, this means writing code to
call
the Simple MAPI functions in another language which can handle the
structures, like C or C++.
- A temporary resolution is to check if Outlook Express is the default Mail
Client, and if it is, to add a DllPathEx key:
HKEY_LOCAL_MACHINE\SOFTWARE\Clients\Mail\Outlook Express::DllPathEx =
%ProgramFiles%\Outlook Express\msoe.dll
This will work because Outlook Express does implement and export the
BMAPIFunctions from msoe.dll. Setting DllPathEx allows the Stub Library
to
route calls to them. The danger in doing this is that an unsuspecting
client
attempting to use Extended MAPI will get the PreFirstRun message (because
msoe.dll does not export the Extended MAPI functions) when it might
instead
have used mapi32x.dll successfully.
- Finally, to make an application use the Outlook Express implementation
for
all MAPI calls, create a new value under the following key:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows Messaging
Subsystem\MSMapiApps
Set the name to the name of your application (MyApp.exe) and the value to
Outlook Express. This short circuts the stub library and forces it to
pass
all MAPI calls, including the BMAPI calls, directly to Outlook Express.
STATUS
======
This behavior is by design.
MORE INFORMATION
================
This happens most often when Outlook Express is set as the Default Mail
Client.
To explain the problem, we need to know a little about how the MAPI Stub
Library
(Mapi32.dll) works. This dll is the one typically loaded by client
application
to make use of Simple MAPI. The purpose behind the stub library is to route
calls made to it on to the appropriate implementation based on registry
settings. In this way, various implementations of MAPI can coexist without
overwriting each other.
When a call is made to a function exported by the stub library, the library
determines if the function is an Extended MAPI function or a Simple MAPI
function. It then looks in
HKEY_LOCAL_MACHINE\SOFTWARE\Clients\Mail::(default)
to determine which MAPI implementation is the current default. It then looks
under the client's key (such as
HKEY_LOCAL_MACHINE\SOFTWARE\Clients\Mail\Microsoft Outlook
for Outlook) to find the value of DllPath or DllPathEx. These keys give
paths to
the appropriate DLLs for Simple MAPI and Extended MAPI, respectively. If the
function is a Simple MAPI function, it loads the DLL given under DllPath and
calls the function. If it is an Extended MAPI function, it loads the Dll
given
under DllPathEx instead.
The following export functions are marked in the stub library as being
Simple
MAPI functions and will be called using the DLL given under DllPath:
- MAPIAddress
- MAPIDeleteMail
- MAPIDetails
- MAPIFindNext
- MAPIFreeBuffer
- MAPILogoff
- MAPILogon
- MAPIReadMail
- MAPIResolveName
- MAPISaveMail
- MAPISendDocuments
- MAPISendMail
All other export functions will use the DLL listed under DllPathEx.
If DllPathEx or DllPath is not found when looked for, then the Stub library
will
use the file mapi32x.dll, located in the same directory as the Stub Library.
This file is typically a renamed copy of the mapi32.dll that already existed
when the Stub Library was installed. On many systems, especially those where
only Outlook and Outlook Express have been installed, this file will not
exist.
If the stub library fails to find mapi32x, it will display the message in
either
HKEY_LOCAL_MACHINE\SOFTWARE\Clients\Mail::PreFirstRun
or
HKEY_LOCAL_MACHINE\SOFTWARE\Clients\Mail::NoMailClient
So, given this information, we can piece together why some Simple MAPI code
will
fail:
1. Most VB code use Declare statements based on
Q163216 Updated Mapivb32.bas for Simple MAPI on 32-Bit Platforms
that import MAPISendMail as BMAPISendMail. Most, but not all, of the
other
SimpleMAPI functions are also declared with their BMAPI equivalents.
2. Since the BMAPI functions are not on the list of Simple MAPI functions
which
use DllPath, the stub library routes them based on DllPathEx.
3. Outlook Express does not implement Extended MAPI, so it has no value set
for
DllPathEx.
4. The stub library will try to use MAPI32x.dll, which doesn't exist, and
end up
displaying the PreFirstRun message.
REFERENCES
==========
Q163216 Updated Mapivb32.bas for Simple MAPI on 32-Bit Platforms
"
I hope this helps.
Fauzia Awan
Microsoft Developer Support - Messaging
This posting is provided "AS IS" with no warranties, and confers no rights.
© 2001 Microsoft Corporation. All rights reserved.