Solved

Using MAPI

Posted on 1998-06-22
13
706 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
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

825 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