2
votes

I am currently using Delphi 7 on XP, but I would like to eventually migrate the code to DXE on Win8.

I am trying to send email using the JCL, using JCLMAPI to be specific. I tried using the JclSimpleSendMail routine in the JCLMAPI unit. Here's the interface to the call.

function JclSimpleSendMail(const Recipient, Name, Subject, Body: AnsiString;   const Attachment: TFileName; ShowDialog: Boolean; ParentWND: THandle;   const ProfileName: AnsiString; const Password: AnsiString): Boolean;

The problem is it pops up the default MAPI client message box modally (in my case Outlook 2010). I would like it to just open the email message window, but allow the user to continue working in the Delphi App. until they are ready to send, eg, in case a user wants to continue working in the Delphi App before sending the email. Is this possible?

I noticed there is a ParentHWND property in TJCLEmail, I tried setting that to zero (I know it was a reach), but I was hoping that removing the parent handle might change the modal behavior (no luck!)

function TForm1.SimpleSendHelper2(const ARecipient, AName, ASubject, ABody: AnsiString; const AAttachment: TFileName;
  AShowDialog: Boolean; AParentWND: THandle; const AProfileName, APassword, AAddressType: AnsiString): Boolean;
var
  AJclEmail: TJclEmail;
begin
  AJclEmail := TJclEmail.Create;
  try
    **AJCLEmail.ParentWnd := 0;  //TRIED FORCING THE ATTACHED HANDLE TO ZERO**
    *//if AParentWND <> 0 then  
    //      AJclEmail.ParentWnd := AParentWND;*
    if ARecipient <> '' then
      AJclEmail.Recipients.Add(ARecipient, AName, rkTO, AAddressType);
    AJclEmail.Subject := ASubject;
    AJclEmail.Body := ABody;
    if AAttachment <> '' then
      AJclEmail.Attachments.Add(AnsiString(AAttachment));
    if AProfileName <> '' then
      AJclEmail.LogOn(AProfileName, APassword);
    Result := AJclEmail.Send(AShowDialog);
  finally
    AJclEmail.Free;
  end;
end;

This also successfully opened up the Default MAPI app and filled in all of the information passed (TO, Subject, Body, Attachment). Unfortunately it still opens the message box modally.

Finally, I also tried the code at http://www.delphifaq.com/faq/delphi/network/f236.shtml This code just Uses MAPI directly (no JCL). Unfortunately, it also pops up the message box modally.

Any thoughts on how I can open the default MAPI client non-modally?

Thank you!

1
Be aware that using MAPI to send e-mails is not necessarily the best solution. A 32-bit application can't use MAPI when 64-bit Outlook is installed for example. - Andy_D
@Andy MAPISendMail should work in any case, even from 32bit app with 64bit Outlook installed: msdn.microsoft.com/en-us/library/office/… - Andrei Galatyn
@AndreiGalatyn That article only applies to Windows 7, not any other 64-bit OS. - Andy_D
@Andy: In our x32 applications we use MAPI to send emails. It works at Win 8 with x64 Outlook 2013 without any problems (fixmapi.exe is still here). There was problem with combination Win7+x64 Office2013, but it is seems to be bug of MS. Article "Building MAPI Applications on 32-Bit and 64-Bit Platforms" is quite general, only one explanation is marked as specific for Win7 (they didn't know how they can implement it in future versions). If you suggest not to use MAPI, then be so kind and suggest what to use instead. - Andrei Galatyn
@Andy, AndreiGalatyn, thanks for both of your responses. I do believe it will work as well, that said, Andy, I too am interested in hearing of an alternative approach. - sse

1 Answers

3
votes

You can use Windows API function MAPISendMailW with flag MAPI_DIALOG_MODELESS assigned. But then you have to use MAPISendMailHelper function for Win8 and later and MAPISendMailW for Windows 7 and earlier. And for Windows 7 such functionality available only with some (latest) versions of Office and only with Windows SDK for Windows 8 installed (according to MSDN). If another email client used (not MS Outlook), then there is no guarantee to get it working.

In other words, it is possible, but it is tricky. I suggest you keep it in modal form, it is safer for many reasons. If user "is not ready to send email", then he will not activate such function (or cancel it to return to the program).