CODE SAMPLE: Here is Microsoft MAPI support with OCX

Post Reply
Rochinha
Posts: 309
Joined: Sun Jan 08, 2006 10:09 pm
Location: Brasil - Sao Paulo
Contact:

CODE SAMPLE: Here is Microsoft MAPI support with OCX

Post by Rochinha »

Code complete:

Code: Select all

// FiveWin OLE support demo
// Using Microsoft MAPI Control
// By Rochinha - Brazil

#include "FiveWin.ch"

#define SESSION_SIGNON  1
#define MESSAGE_COMPOSE 6
#define ATTACHTYPE_DATA 0
#define RECIPTYPE_TO    1
#define RECIPTYPE_CC    2
#define MESSAGE_RESOLVENAME 13
#define MESSAGE_SEND    3
#define SESSION_SIGNOFF 2

function Main()
   local oWnd

   DEFINE WINDOW oWnd TITLE "FiveWin OLE Support"

   MapiSession1  := TOleAuto():New( "MSMAPI.MAPISession.1" )
   MapiMessages1 := TOleAuto():New( "MSMAPI.MAPImessages.1" )

   //MapiSession1:aboutbox()
   //Open up a MAPI session
   MapiSession1:Action      := SESSION_SIGNON
   //Point the MAPI messages control to the open MAPI session:
   MapiMessages1:SessionID  := 1

   MapiMessages1:Action     := MESSAGE_COMPOSE   //Start a new message

   // Set the subject of the message:
   MapiMessages1:MsgSubject := "This is the subject."
   // Set the message content
   MapiMessages1:MsgNoteText:= "This is the mail message."

   // The following four lines of code add an attachment to the message,
   // and set the character position within the MsgNoteText where the
   // attachment icon will appear. A value of 0 means the attachment will
   // replace the first character in the MsgNoteText. You must have at
   // least one character in the MsgNoteText to be able to attach a file.
   MapiMessages1:AttachmentPosition := 0
   // Set the type of attachment
   MapiMessages1:AttachmentType     := ATTACHTYPE_DATA
   // Set the icon title of attachment:
   MapiMessages1:AttachmentName     := "System Configuration File"
   // Set the path and file name of the attachment:
   MapiMessages1:AttachmentPathName := "C:\CONFIG.SYS"

   // Set the recipients
   MapiMessages1:RecipIndex       := 0                  // First recipient
   MapiMessages1:RecipType        := RECIPTYPE_TO       // Recipient in TO line
   MapiMessages1:RecipDisplayName := "EddieSpaghetti"   // e-mail name
   MapiMessages1:RecipIndex       := 1                  // add a second recipient
   MapiMessages1:RecipType        := RECIPTYPE_TO       // Recipient in TO line
   MapiMessages1:RecipDisplayName := "TanyaLasagna"     // e-mail name
   MapiMessages1:RecipIndex       := 2                  // Add a third recipient
   MapiMessages1:RecipType        := RECIPTYPE_CC       // Recipient in CC line
   MapiMessages1:RecipDisplayName := "BlairAngelHair"   // e-mail name
   MapiMessages1:RecipIndex       := 3                  // Add a fourth recipient
   MapiMessages1:RecipType        := RECIPTYPE_CC       // Recipient on CC Line
   MapiMessages1:RecipDisplayName := "JoanieCannelloni" // e-mail name"

   // MESSAGE_RESOLVENAME checks to ensure the recipient is valid and puts
   // the recipient address in MapiMessages1:RecipAddress
   // If the E-Mail name is not valid, a trappable error will occur.
   MapiMessages1:Action := MESSAGE_RESOLVENAME
   // Send the message:
   MapiMessages1:Action := MESSAGE_SEND

   // Close MAPI mail session:
   MapiSession1:Action := SESSION_SIGNOFF

   ACTIVATE WINDOW oWnd

return nil
Download de .OCX
http://home.wxs.nl/~hafoh000/MSMAPI32.zip
User avatar
Taiwan
Posts: 218
Joined: Fri Oct 07, 2005 1:55 am
Location: Taipei, Taiwan
Contact:

Post by Taiwan »

Hello Rochinha,

Thanks for your help and file.
I will get new skill for it.

But I got this error message

Error description: Error TOleAuto/-1 Unknown error: TOLEAUTO:NEW

Regards,

Richard
Last edited by Taiwan on Fri Mar 09, 2007 8:31 am, edited 1 time in total.
JoseLuis
Posts: 359
Joined: Thu Oct 19, 2006 12:28 pm
Location: Toledo

Post by JoseLuis »

Hola

Gracias por el código, lo que pasa es que, aunque me compila perfectamente, cuando ejecuto la aplicación me da el siguiente error:
Error description: Error TOleAuto/-1 Unknown error: TOLEAUTO:NEW

Que puede ser?

Saludos

Jose Luis
Rochinha
Posts: 309
Joined: Sun Jan 08, 2006 10:09 pm
Location: Brasil - Sao Paulo
Contact:

Post by Rochinha »

Excuse me friends,

Download the .OCX on link below and register in your system first:

http://home.wxs.nl/~hafoh000/MSMAPI32.zip

COPY MSMAPI32.OCX C:\WINDOWS\SYSTEM32
CD WINDOWS\SYSTEM32
REGSVR32.EXE MSMAPI32.OCX

I'm use a tradicional Harbour, not xHarbour.

Change the TAutoOLE() to CreateOLEObject()

MapiSession1 := CreateOLEObject( "MSMAPI.MAPISession.1" )
MapiMessages1 := CreateOLEObject( "MSMAPI.MAPImessages.1" )

And set properties and methods to:

Properties:

OLESetProperty(MapiSession1,"property",value)
OLEGetProperty(MapiSession1,"property")

Methods:

OLEInvoke(MapiSession1,"method")
Rochinha
Posts: 309
Joined: Sun Jan 08, 2006 10:09 pm
Location: Brasil - Sao Paulo
Contact:

Post by Rochinha »

Here is the Send/Receiving code:

Code: Select all

// FiveWin OLE support demo - Using Microsoft MAPI Control

#include "FiveWin.ch"

#define SESSION_SIGNON  1
#define MESSAGE_COMPOSE 6
#define ATTACHTYPE_DATA 0
#define RECIPTYPE_TO    1
#define RECIPTYPE_CC    2
#define MESSAGE_RESOLVENAME 13
#define MESSAGE_SEND    3
#define SESSION_SIGNOFF 2

function Main()
   local oWnd, aMessages := {}

   SET DATE BRIT
   // 
   // FiveWin OLE Support - Sending
   // 
   MapiSession1  := TOleAuto():New( "MSMAPI.MAPISession.1" )
   MapiMessages1 := TOleAuto():New( "MSMAPI.MAPImessages.1" )

   //MapiSession1:aboutbox()
   //Open up a MAPI session
   MapiSession1:Action      := SESSION_SIGNON
   //Point the MAPI messages control to the open MAPI session:
   MapiMessages1:SessionID  := MAPISession1:SessionID

   MapiMessages1:Action     := MESSAGE_COMPOSE   //Start a new message

   // Set the subject of the message:
   MapiMessages1:MsgSubject := "This is the subject."
   // Set the message content
   MapiMessages1:MsgNoteText:= "This is the mail message."

   // The following four lines of code add an attachment to the message,
   // and set the character position within the MsgNoteText where the
   // attachment icon will appear. A value of 0 means the attachment will
   // replace the first character in the MsgNoteText. You must have at
   // least one character in the MsgNoteText to be able to attach a file.
   MapiMessages1:AttachmentPosition := 0
   // Set the type of attachment
   MapiMessages1:AttachmentType     := ATTACHTYPE_DATA
   // Set the icon title of attachment
   MapiMessages1:AttachmentName     := "System Configuration File"
   // Set the path and file name of the attachment
   MapiMessages1:AttachmentPathName := "C:\CONFIG.SYS"

   // Set the TO recipients
   aTORecipients := { "softclever@itelefonica.com.br", ;
                      "irochinha@itelefonica.com.br", ;
                      "fivolution@hotmail.com", ;
                      "softclever@ig.com.br" }
   aCCRecipients := { RECIPTYPE_TO, RECIPTYPE_CC, RECIPTYPE_CC, RECIPTYPE_CC }
   for i = 1 to len(aTORecipients)
       MapiMessages1:RecipIndex          := i                  // Recipient count
       MapiMessages1:RecipType           := aCCRecipients[i]   // Recipient in TO line
       MapiMessages1:RecipDisplayName    := aTORecipients[i]   // e-mail name
       MapiMessages1:MsgReceiptRequested := .t.
   next

   // MESSAGE_RESOLVENAME checks to ensure the recipient is valid and puts
   // the recipient address in MapiMessages1:RecipAddress
   // If the E-Mail name is not valid, a trappable error will occur.
   MapiMessages1:Action := MESSAGE_RESOLVENAME
   // Send the message
   MapiMessages1:Action := MESSAGE_SEND

   // Close MAPI mail session
   MapiSession1:Action := SESSION_SIGNOFF

   MapiSession1:End()
   MapiMessages1:End()

   //
   // FiveWin OLE Support - Receiving
   //
   MapiSession1  := TOleAuto():New( "MSMAPI.MAPISession.1" )
   MapiMessages1 := TOleAuto():New( "MSMAPI.MAPImessages.1" )
    
   MAPISession1:DownLoadMail := .t.
   MAPISession1:SignOn()
    
   MAPIMessages1:SessionID := MAPISession1:SessionID
   MAPIMessages1:Fetch()

   nMsgHoje := 0
   nMsgLida := 0

   If MAPIMessages1:MsgCount > 0
      For i = 0 To MAPIMessages1:MsgCount - 1
          MAPIMessages1:MsgIndex := i
          if MDtoD( MAPIMessages1:MsgDateReceived ) = date()
             nMsgHoje := nMsgHoje + 1
          endif
          if MAPIMessages1:MsgRead
             nMsgLida := nMsgLida + 1
          endif
          AADD( aMessages, { "From: " + MAPIMessages1:MsgOrigDisplayName, ;
                             "Subject: " + MAPIMessages1:MsgSubject } )
      Next
   End If
   MAPISession1:SignOff()

   MapiSession1:End()
   MapiMessages1:End()

   ? "Menssages: "+str(len( aMessages )), "Today: "+str(nMsgHoje), "Reads: "+str(nMsgLida)

return nil

Function MDtoD( cData )
   cData := substr( cData, 1, 10 )
   return ctod( substr(cData,9,2)+"/"+substr(cData,6,2)+"/"+substr(cData,1,4) )
JoseLuis
Posts: 359
Joined: Thu Oct 19, 2006 12:28 pm
Location: Toledo

Post by JoseLuis »

Hola Rochinha
Yo utilizo xharbour+verce, y siempre que quiero utilizar Toleauto:New, me da error, y es que no se si tengo que enlazar con alguna libreria o qué.
Como has indicado, he sustituido

Code: Select all

   MapiSession1  := TOleAuto():New( "MSMAPI.MAPISession.1" ) 
   MapiMessages1 := TOleAuto():New( "MSMAPI.MAPImessages.1" ) 
por

Code: Select all

MapiSession1 := CreateOLEObject( "MSMAPI.MAPISession.1" ) 
MapiMessages1 := CreateOLEObject( "MSMAPI.MAPImessages.1" ) 
y ahora me sale en tiempo de ejecución el siguiente error:

" Error description: Error BASE/1005 Class: 'NUMERIC' has no property: ACTION"

Este error hace referencia a ésta línea:

" MapiSession1:Action := SESSION_SIGNON "

Me das algún consejo?

Saludos

Jose Luis
User avatar
Ari
Posts: 128
Joined: Fri Feb 03, 2006 4:21 pm
Location: Brazil
Contact:

Post by Ari »

eu recebi o mesmo erro que o Jose Luiz

Ari
User avatar
anserkk
Posts: 1280
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Re: CODE SAMPLE: Here is Microsoft MAPI support with OCX

Post by anserkk »

¿Hay alguien aquí trató de leer un servidor POP3 para descubrir nuevos correos no leídos en un servidor POP3.

También estoy recibiendo el mismo error.

Si puedo comprobar el ValType de

Code: Select all

MapiSession1: = CreateOleObject ( "MSMAPI.MAPISession.1")
Se trata de "N" (numérico)

Me estoy haciendo el mismo error que José Luis y Ari
¿Hay algo malo?. ¿Alguien trató este

Saludos
Anser
Post Reply