[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Using MAPI

Posted on 1998-06-22
13
Medium Priority
?
732 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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
 
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 400 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

834 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