Class: cMapiHandler
Properties | Events | Methods | Index of Classes
Consists of functions for sending mail, reading received mail and sending documents
Hierarchy
cObject > cMapiHandler
Show full hierarchy and direct subclasses
- cObject
- cMapiHandler
Library: Common Class Library
Package: cMapiHandler.Pkg
Description
This class is obsolete, since Simple MAPI was deprecated by Microsoft.
Simple MAPI consists of functions for sending mail, reading received mail and sending documents. Consider MAPI as a transport mechanism for mail and fax messages. Connected to a message we can send enclosures. It is usually default installed on your and the customer's computer in the form of a DLL. Many software packages do use the Windows MAPI layer for sending and receiving mail. Microsoft Outlook does also use MAPI but adds many extra features on top of it. Do not confuse the functionality of Outlook with MAPI via DataFlex. The common part of it is sending and reading mail. If you need the functionality of Outlook (read from other Outlook or compliant product folders for example) inside your applications you should create an Outlook Active-X connection.
To establish a connection between your application and the Windows MAPI you need to create an object of the cMapiHandler class. A global cMapiHandler object will be created. Using multiple cMapiHandler objects makes it possible to use multiple profiles/accounts from within one DataFlex application. Using one object makes it possible to globally logon/logoff to MAPI and makes sending messages easier.
Sending Mail
To be able to send mail to an addressee one needs to fulfill the following requirements: Login to the MAPI system and get a MAPI Handle.Initialize the DataFlex MAPI elements. This way a new message can be a composed.Specify the message subject and body (text of the message).Specify at least one addressee.Specify enclosures/attachments if you want.Send the message.Logoff from the MAPI system. Of course, you can leave the logon/logoff out of the above scheme if you want to do this once.
Reading Mail
Only already received mail (placed in the INBOX) can be read. Do the following: Login to the MAPI system and get a MAPI Handle.Scan for messages (new or already as read marked messages).Process each message that is placed in the properties of your cMapiHandler object.Logoff from the MAPI system. Of course, you can leave the logon/logoff out of the above scheme if you want to do this once.
User interface sample
Study the MAPI sample installed in the Examples directory. These are only examples of how you could use it. The components are reusable.
Manually compose/send a message
When you want to send a message via MAPI without using the dialogs (UI) you can use the code from the following sample as an example.
Use Windows.pkg
Use DFError.pkg
Use MapiSession.Pkg
// In this method we will demonstrate how to send a message using NEW MAPI
// without using visual controls
Procedure DoCreateSendMessage
Integer iRetVal
Handle hoMapiSession
Move oMapiSession To hoMapiSession
If (hoMapiSession > 0) Begin
Send DoInit To hoMapiSession
Set psMessageSubject Of hoMapiSession To "A test message for the book"
Set psMessageText Of hoMapiSession To ("This is line 1 of the message body" + Character (13) + Character (13) + "and this is line 3")
Send DoAddReceiver To hoMapiSession MAPI_TO "somename" "SMTP:somename@somehost.com" "" 0
Get Logon Of hoMapiSession "" "" 0 To iRetval
Get SendMail Of hoMapiSession (MAPI_NEW_SESSION iOr MAPI_LOGON_UI) True To iRetval
Get Logoff Of hoMapiSession To iRetval
End
End_Procedure
Send DoCreateSendMessage
As an extra you can set the psUsername and psPassword properties or replace the "0" in the Get Logon. line with MAPI_LOGON_UI constant. This will popup a logon dialog in which the user can select the profile to use and if required specify a password.
Since the default for pbReportErrors property is false, you have to check the results of the MAPI functions and see whether you want to continue the operation or not. You can find samples of this usage in the sample dialogs and MAPI view.
Sample
Object oMapiSession is a cMapiHandler
End_Object