Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Mapi Session and Mapi Message

Status
Not open for further replies.

Kurjo

Programmer
May 13, 2003
67
US
Hi,

It looks like very simple, but I have no clue how it get work.

I have a form and I put two activex controls in it (I know they are required to send mail) Mapi Session and Mapi Messages.

Can somebody help describing what are the steps to use these activex control and send mail.

My main concern is that how do I connect the session that created by Mapi session to Mapi Messages. When I try to compose a message using Mapi Message I am getting error message 'A Valid session id not exist'.

I know that there are other ways (CDO, SMTP, Senddocuments, ShellExecute etc.) to send mail but most of them are poping up dialog box to send the mail. I want to send the email automatically without user invervention.

Any Help appreciated.
 
Kurjo
Take a look at faq184-1769 or this following:

Code:
   oform = CreateObject("form")
   oform.addobject("Session1","olecontrol","MSMAPI.mapiSession")
   oform.addobject("Message1","olecontrol","MSMAPI.mapiMessages")
   oform.Session1.signon
   oform.Message1.sessionid = oform.Session1.sessionid
   oform.Message1.compose
   oform.Message1.msgsubject = "Memo from my FoxPro app"
   oform.Message1.msgnotetext = "This works"
   oform.Message1.send(1)
   oform.Session1.signoff
   release oform

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Tanks Mike,

It is working. I have one more question, Is there any way that I can send the email without user intervention using this. This pops up the email dialog that the user have to click the send button.

Thanks again for your help.

Kurjo
 
Kurjo

The one I'm currently using (which we use to advise users of certain network activity and does not pop-up) is Rick Strahl's wwIpstuff.

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Hi Mike,

Thanks again. I solved the problem without using wwIp
stuff.

parameter lcaddress,lcSubject,lcBody,lcAttachment
oform = CreateObject("form")
oform.addobject("Session1","olecontrol","MSMAPI.mapiSession")
oform.addobject("Message1","olecontrol","MSMAPI.mapiMessages")
oform.Session1.signon
oform.Message1.sessionid = oform.Session1.sessionid
oform.Message1.compose
oform.Message1.msgIndex = -1
oform.Message1.RecipDisplayName = lcaddress
oform.Message1.ResolveName
oform.Message1.msgsubject = lcSubject
oform.Message1.msgnotetext = lcBody
IF NOT EMPTY(lcAttachment)
oform.Message1.AttachmentPathname =lcAttachment
ENDIF

IF EMPTY(lcAddress) OR EMPTY(lcSubject)
oform.Message1.send(1)
ELSE
oform.Message1.send(0)
ENDIF
oform.Session1.signoff
release oform

Here it will show the dialog only if the address or subject are empty.

Kurjo
 
Hi Mike,

Even if I succeeded with this application in my development machine in the user computer I encounter some problem. I register MSMAPI32.OCX in the user machine. But when I run the program I am getting the Ole error 'Class is not Licensed to use'.

Am I doing the right thing here? or do I have to register some other class? Also I copied this OCX file in the application directory.

Your help is greatly appreciated.

Kurjo
 
Kurjo,
This "problem" is a variant (different OCX) of the one described in - "INFO: OLE Control Licensing in Visual FoxPro (Q139154)". The final example shows a way around the problem.

You may want to also read - "BUG: License Error with ActiveX Control Added at Run-Time (Q192693)"

For some actual code, the following is currently working just fine in many locations (VFP 6.0 SP5). Basically, because the VCX does the direct usage of Winsock, and it's precompiled, it doesn't create a license problem! It's a simple procedure that uses Winsock to get the IP address. (Andy is one of our programmers.)
Code:
* Program....: GETIP.PRG
* Version....: 1.0
* Author.....: ** Andy Goeddeke **
* Date.......: January 8, 2002
* Return IP address as char string

* 02/04/2002 Changed the technique slightly to avoid the "Class not
registered/licensed" errors.

*!* The following DOESN'T work!
*!*    LOCAL loWinsock
*!*    loWinSock = CREATEOBJECT("MSWinsock.Winsock")
*!*    return loWinsock.LocalIP

LOCAL oForm1, lcIP
oForm1 = CREATEOBJECT("dummyform")
lcIP = oForm1.Olecontrol1.LocalIP
RELEASE oForm1
RETURN lcIP

*************************************
DEFINE CLASS dummyform AS form

  DoCreate = .T.
  Caption = "dummyform"
  Name = "dummyform"

  PROCEDURE INIT
    IF .F.
      ** This sucks the class into the project automatically.
      SET CLASS TO ep_winsock
    ENDIF
    THISFORM.NewObject("olecontrol1", "ep_winsock", "ep_winsock")
  ENDPROC

ENDDEFINE

*** Where ep_winsock.vcx is (code from class browser):
**************************************************
*-- Class:        ep_winsock (..\classlibs\ep_winsock.vcx)
*-- ParentClass:  olecontrol
*-- BaseClass:    olecontrol
*-- Time Stamp:   02/04/02 10:38:02 AM
*-- OLEObject = C:\WINNT\SYSTEM32\MSWINSCK.OCX
*
DEFINE CLASS ep_winsock AS olecontrol
  Height = 100
  Width = 100
  Name = "ep_winsock"

ENDDEFINE
*
*-- EndDefine: ep_winsock
**************************************************
Rick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top