Solved

Using MAPI

Posted on 1998-06-22
13
702 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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

708 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

17 Experts available now in Live!

Get 1:1 Help Now