How to Send an OLE Object in Mail from Within FoxPro

Last reviewed: April 29, 1996
Article ID: Q107831
The information in this article applies to:
  • Microsoft FoxPro for Windows, versions 2.5, 2.5a, and 2.5b

SUMMARY

The FoxPro Extensions that come with the Workgroup templates enable FoxPro developers to tap into the mail messaging API (MAPI) and the Microsoft Schedule+ API (SPLUS). Below is a simple example of how to send an embedded OLE object in a mail message from FoxPro for Windows.

MORE INFORMATION

The FoxPro Extensions come with FOXMAPI.FLL, MAPILIB.PRG, and MAPIERR.PRG.

  • FOXMAPI.FLL is a DLL that is the interface between FoxPro and the MAPI.DLL and SPLUS.DLL.
  • MAPILIB.PRG is a file containing procedures that make calls to functions in the FOXMAPI.FLL. (Instead of calling the functions in FOXMAPI.FLL directly, you can pass parameters to MAPILIB.PRG, which does extra error checking.)
  • MAPIERR.PRG is called by MAPILIB.PRG if an error condition occurs when a procedure in MAPILIB.PRG is executing.

For more information about the functions used in this example, examine the MAPILIB.PRG file to find the function that is called in MAPILIB.PRG and then see what function MAPILIB.PRG calls in FOXMAPI.FLL. The Help file located in WGTPLATE\APPENDIX\FOXPRO\FOXMAPI.HLP explains what the functions in FOXMAPI.FLL do.

The example below will send the CARS.BMP bitmap file specified by the variable M.PATHNAME to the person that is specified in the M.TONAMES variable.

For the following example to work, you must have FOXMAPI.FLL, MAPILIB.PRG, and MAPIERR.PRG. MAPILIB.PRG and MAPIERR.PRG should be located in the same directory as the program below.

   ** Unload any library that is in memory.
   SET LIBRARY TO

   ** SET THE LIBRARY TO FOXMAPI.FLL
   SET LIBRARY TO foxmapi.fll

   ** NOTE: MAPILIB.PRG and MAPIERR.PRG need to be in the same
   ** directory as this program for things to work properly.

   ** MAPILIB.PRG calls FOXMAPI.FLL
   ** Log on to mail and get session handle
   msession=MAPILIB('LOGON')

   ** Get info to send
   ** m.tonames- the e-mail name of the person the message is addressed
   ** to.
   ** m.subject- the subject line of the e-mail message.
   ** m.notetext- the text of the e-mail message.
   m.tonames="JOHN DOE"
   m.subject="ATTACH MAIL TEST"
   m.notetext=SPACE(200)

   m.position=1             && This position is where to insert object
   m.pathname="c:\windows\cars.bmp"  && Path and file of OLE object
   m.filename=""            && Indicates to use pathname

   ** create mapiRecip cursor
   ** resolve name
   ** The MapiRecip cursor contains information about a message
   ** originator or recipient.
   =MAPILIB('resolve',msession,m.tonames)

   ** Create mapiFile and mapiMesg cursors.
   ** mapiFile contains information about a file attachment.
   ** mapiMesg contains information about a message.
   ** See the help file for more information.
   =MAPILIB('newcursor','mapiFile')
   =MAPILIB('newcursor','mapiMesg')

   ** Insert the needed information.
   INSERT INTO mapiFile VALUES(0,0,1,m.pathname,m.filename,;
      "")

   INSERT INTO mapiMesg VALUES(0,m.subject,m.notetext,'IPM.',;
      MAPILIB('getdate'),'',0,RECCOUNT('mapiRecip'),1)

   retval=mapilib("sendmail",msession,"mapiMesg","mapiRecip",;
      "mapiFile",0)

   ** Log off and cleanup
   ** Logging off by directly calling the mplogoff function in
   ** FOXMAPI.FLL
   =MPLogoff(msession,0,0,0)

   CLEAR ALL
   CLOSE ALL
   RELEASE ALL
   SET LIBRARY TO
   ** END OF PROGRAM


Additional reference words: FoxWin 2.50 2.50a 2.50b mapi ext
email
KBCategory: kbole kbprg kbcode
KBSubcategory: FxinteropOle


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: April 29, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.