Solved

Using MAPI

Posted on 1998-06-22
13
703 Views
Last Modified: 2010-04-04
At first sorry for my english...

I'm not new in Delphi but have a problem with MAPI in Delphi (ver. 3.01).

This is part of my program, its work well... but after exiting this procedure (TForm.Button2Click) is error occured (something like "access violation .... read of addres xxxxxxxx"). Im trying it on Exchage and OutLook...


{===================}
procedure TForm1.Button2Click(Sender: TObject);
var m, Seedm:LPSTR; ulResult:cardinal; h:hWnd; pf,ps:string;
begin

hSession:=0;
if hSession=0
   then ulResult:=MAPILogon(0,nil,nil, MAPI_LOGON_UI ,0,@hSession);

ulResult:=MAPIFindNext(hSession,0,nil,nil,0,0,m);
while ulResult=SUCCESS_SUCCESS do
begin
SeedM:=M;
ulResult:=MAPIFindNext (0,0,Nil,SeedM,MAPI_GUARANTEE_FIFO or MAPI_LONG_MSGID,0,M);
end;
{ReadMail;}
MAPILogoff (hSession,0,0,0);
hSession:=0;
end;
{================}

Thank you.
marsat.marinfo@comset.net
0
Comment
Question by:AlexanderA
  • 6
  • 5
  • 2
13 Comments
 

Author Comment

by:AlexanderA
ID: 1355013
Edited text of question
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1355014
Hi AlexanderA,

Don't search anymore on this subject ;-) Look at the source of this freeware component ... or just use it!.

Excelent demo's and good documents.

temail2.zip at Torries!

torry.rimini.com/vcl/internet/temail2.zip.

Regards, Zif.
0
 

Author Comment

by:AlexanderA
ID: 1355015
From: ZifNab Date: Monday, June 22 1998 - 02:42AM PDT  
Hi AlexanderA,
Don't search anymore on this subject ;-) Look at the source of this freeware component ... or just use it!.
Excelent demo's and good documents.
temail2.zip at Torries!
torry.rimini.com/vcl/internet/temail2.zip.
Regards, Zif.

Im ulready have using this component, but error still occured,
may be this is a Delphi error? Or OutLook problem? But im trying it on many computer.

Im desperate...
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1355016
where is hSession defined?
0
 
LVL 3

Expert Comment

by:vladika
ID: 1355017
You did not allocate space for M and Seedm

As write in help for MAPIFindNext
MessageID
Output parameter specifying the returned message identifier. The MessageID parameter is a variable-length string allocated by the CALLER. To ensure compatibility, ALLOCATE 512 characters. A smaller buffer will only be sufficient if the returned message identifier will always be 64 characters or less.
0
 

Author Comment

by:AlexanderA
ID: 1355018
From: ZifNab Date: Monday, June 22 1998 - 04:03AM PDT  
where is hSession defined?
 
Dont worry - all variable defined and space is allocated,
its just a part of my program...

OK.  
Excelent demo's and good documents.
temail2.zip at Torries!
torry.rimini.com/vcl/internet/temail2.zip.

This component doesnt working too (its working but error occured /see my original message/)
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 3

Expert Comment

by:vladika
ID: 1355019
Please, write full version of TForm1.Button2Click(Sender: TObject);
0
 
LVL 3

Expert Comment

by:vladika
ID: 1355020
Why do you not use hSession in
  ulResult:=MAPIFindNext (0,0,Nil,SeedM,MAPI_GUARANTEE_FIFO or MAPI_LONG_MSGID,0,M); ?

The value of the Session parameter must represent a valid session; it CANNOT BE ZERO.

0
 

Author Comment

by:AlexanderA
ID: 1355021
>Why do you not use hSession in
>  ulResult:=MAPIFindNext (0,0,Nil,SeedM,MAPI_GUARANTEE_FIFO or >MAPI_LONG_MSGID,0,M); ?
>The value of the Session parameter must represent a valid >session; it CANNOT BE ZERO.

OK. Just run my code and try to do this...
Im feel myself a little stupid.
Ok, part with FindNext is working now - thanks to Vladika, (im allocate to small space for PChar).

BUT now the other part doesnt working (the error occured on EXIT of program - a little strange):

procedure TForm1.Button2Click(Sender: TObject);
var m, Seedm:PChar; ulResult:cardinal; h:hWnd; i:integer;
lpMapiMessage: PMapiMessage;
begin
m := Stralloc(600);
FillChar(m^, 600,0);
Seedm := Stralloc(600);
FillChar(Seedm^, 600,0);

hSession:=0;
 if hSession=0
    then ulResult:=MAPILogon(0,nil,nil, {MAPI_EXTENDED or }MAPI_LOGON_UI {or MAPI_NEW_SESSION},0,@hSession);
 Form1.memo1.lines.add(IntToStr(ulResult));
 ulResult:=MAPIFindNext(hSession,0,nil,nil,0,0,m);
 Form1.memo1.lines.add(IntToStr(ulResult));
while ulResult=SUCCESS_SUCCESS do
begin
 form1.memo1.lines.add('FindMessage'+m);
 form1.memo2.lines.add(SeedM);
 Application.ProcessMessages;
 StrPCopy(SeedM, M);

 MapiReadMail(0, 0, m,{MAPI_DIALOG or }{MAPI_LOGON_UI or MAPI_NEW_SESSION}0, 0, lpMapiMessage);

{^^^^^ i think problem is here...}

 ulResult:=MAPIFindNext (0,0,Nil,SeedM,MAPI_GUARANTEE_FIFO or MAPI_LONG_MSGID,0,M);
end;
Form1.memo1.lines.add('Mapi get OK');
{ReadMail;}
MAPILogoff (hSession,0,0,0);
hSession:=0;
Form1.memo1.lines.add('Mapi logoff OK');
end;


0
 

Author Comment

by:AlexanderA
ID: 1355022
Still waiting for answers...
Im want to understand how to work with MAPI.
To Vladika - as i know you have MAPI documentation - can you send me some of it??? (MapiReadMail, SendMail, FindNext, Logon, Logoff and so on...), i have download part of SDK (abt 4Mb) but didnt find nothing - only examles in C.

Thank you very much for help.
marsat.marinfo@comset.net
0
 
LVL 3

Accepted Solution

by:
vladika earned 100 total points
ID: 1355023
1) You did not call StrDispose for M and SeedM in the end of procedure
2) M and SeedM is NULL-terminated string, so why are you use StrPCopy?
StrPCopy works for pascal style strings
3) You did not use hSession in MAPIFindNext and MAPIReadMail
4) Check type of hSession (it must be LHANDLE).

Try my procedure

procedure TForm1.Button2Click(Sender: TObject);
type TMapiMessageID = array[0..511] of Char;
var ulResult:cardinal;
    lpMapiMessage: PMapiMessage;
    M, SeedM: TMapiMessageID;
begin
  hSession:=0;
  ulResult:=MAPILogon(0,nil,nil, {MAPI_EXTENDED or }MAPI_LOGON_UI {or MAPI_NEW_SESSION},0,@hSession);
  Memo1.lines.Add('MAPILogon: Result = '+IntToStr(ulResult));
  ulResult:=MAPIFindNext(hSession,0,nil,nil,0,0,M);
  Memo1.lines.Add('MAPIFindNext: Result = ' + IntToStr(ulResult));
  while ulResult=SUCCESS_SUCCESS do
  begin
    Memo1.lines.Add('FindMessage: MsgID='+M);
    Application.ProcessMessages;
    Move(M, SeedM, SizeOf(TMapiMessageID));  // copy M into SeedM

    MapiReadMail(hSession, 0, M,{MAPI_DIALOG or }{MAPI_LOGON_UI or MAPI_NEW_SESSION}0, 0, lpMapiMessage);  // use hSession here

    ulResult:=MAPIFindNext (hSession, 0, nil, SeedM, MAPI_GUARANTEE_FIFO or MAPI_LONG_MSGID, 0, M);  // use hSession here
    Memo1.lines.Add('MAPIFindNext: Result = ' + IntToStr(ulResult));
  end;
  Memo1.lines.add('Mapi get OK');
  {ReadMail;}
  MAPILogoff (hSession,0,0,0);
  hSession:=0;
  Memo1.lines.add('Mapi logoff OK');
end;


0
 
LVL 3

Expert Comment

by:vladika
ID: 1355024
See mapi.pas in Delphi 3\Source\RTL\Win
See mapi.hlp in Delphi 3\HELP

If you have not these files I can send it to you.

0
 

Author Comment

by:AlexanderA
ID: 1355025
Vladika, thank you very much.

I dont believe myself but its working now.

Im just getting started this project - and this is not last my question.

Thank you again.
Write me at -  marsat.marinfo@comset.net
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Convert Jpg /PNG To GIF 5 120
Delphi Dbf export problem to a Visual Foxpro application 6 163
LAN or WAN ? 11 83
Controlled Assessment GCSE - desperate help needed 4 76
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now