Delphi MapiSendMail Crashes on Windows 7 64-bit

2.9k views Asked by At

I have windows 7 64-bit and my delphi sendmail crashes when trying to send an email for the second time or sometimes even just waiting for the first send mail to complete. Same application works with windows vista.

Below is my test procedure in sending the mail:

procedure TForm1.SendMail(const Subject, FileName: String);
var tmpName2, PFullFilePath, PSubject : Array[0..MAX_PATH] of AnsiChar;
    MapiMessage  : TMapiMessage;
    MapiFileDesc : TMapiFileDesc;
    MError       : Cardinal;
begin
  with MapiFileDesc do
  begin
     ulReserved:=0;
     flFlags:=0;
     nPosition:=Cardinal(-1);
     StrPCopy(PFullFilePath, FileName);
     lpszPathName:=PFullFilePath;
     StrPCopy(tmpName2,ExtractFileName(FileName));
     lpszFileName:=tmpName2;
     lpFileType:=nil;
   end;

   with MapiMessage do
   begin
      ulReserved := 0;
      StrPCopy(PSubject, Subject);
      lpszSubject := PSubject;
      lpszNoteText := nil;
      lpszMessageType := nil;
      lpszDateReceived := nil;
      lpszConversationID := nil;
      flFlags := 0;
      lpOriginator := nil;
      nRecipCount := 0;
      lpRecips := nil;
      nFileCount := 1;
      lpFiles := @MapiFileDesc;
   end;

   MError:=MapiSendMail(0,Application.Handle, MapiMessage, MAPI_DIALOG or MAPI_LOGON_UI or MAPI_NEW_SESSION, 0);

   if MError<>0 then
      Raise Exception.CreateFmt(IntToStr(MError), [MError]);
end;

Error/Crash Message that I get:

Problem signature:
Problem Event Name: APPCRASH
Application Name: mapitestp.exe
Application Version: 0.0.0.0
Application Timestamp: 4d82c905
Fault Module Name: ntdll.dll
Fault Module Version: 6.1.7600.16559
Fault Module Timestamp: 4ba9b29c
Exception Code: 4000001f
Exception Offset: 000a1dcf OS Version: 6.1.7600.2.0.0.256.1
Locale ID: 1033
Additional Information 1: d1ab
Additional Information 2: d1ab624ec7d094c26a73530c245a3468
Additional Information 3: d1ab
Additional Information 4: d1ab624ec7d094c26a73530c245a3468

Any help or idea would be very much appreciated. Thanks

1

There are 1 answers

1
CloudyMarble On

Take a look at this Link at Embarcadero, it may be some Unicode issue.

Hope it helps you.