How to write an Pegasus Mail Extension using Delphi 4

Pegasus Mail Screen Shot

What you need:

Unpack the Extension Development Kid and read WpmForms.txt as an introduction. A list and documentation of "functions" provided by Pegasus Mail can be found in WpmForms.h. These two files are the most important ones. The last one is the file that could directly used if the extension would be created in C++.

I'll explain writing an extension in Delphi by showing how to create a senseless extension that shows the directory, where PMail is installed. As said, I use Delphi 4 - for different versions it could be slightly different:

  1. New|DLL: This creates a dpr - file. Save it as DemoPlugin.dpr. Instead of program DemoPlugin; there can be found
    library DemoPlugin;
    You can ignore the warning that you have to use the unit Sharemem and therefore BORLNDMM.DLL: I know no reason why the PMail extension should export or import Delphi - like strings. So don't use the unit Sharemem.
  2. Create a new form (like you are used to form normal Delphi programs)- it will be the main form of your extension. I called the unit UMain.pas and the form FMain (type TFMain). Set BorderStyle to bsNone (because Pegasus Mail provides the wrapping - window).
  3. We'll create this form in DemoPlugin.dpr but we have to destroy it here. So add the following code at the end of UMain.pas:
      FMain := nil;
      if Assigned(FMain) then FMain.Free;
  4. As Wpmforms.txt tells us, we have to export a function called FORMINIT. Pegasus Mail calls it when the user Clicks on the button to call our extension. In this function we have to create the form FMain. Look at the Demoplugin.dpr.
  5. The methods are necessary to draw our form correctly (just try to leave them away ;-) ).
  6. If you add a close button to your form, call PostMessage(ParentWindow, WM_CLOSE, 0, 0); instead of Close;
  7. Look at procedure TFMain.BtnGetBaseDirClick(Sender: TObject); to see how Pegasus Mail and the extension communicate.
  8. From now on, you can write code as you are used to ;-)
  9. Write an fff-file for your extension.
  10. Create a nice Button. Take an existing button as template.
  11. Copy the button, fff-file and dll-filde in the PMail - Directory.

If you want to debug your extension with Delphi, open Start|Parameter and fill in (example):

Further you have to edit the fff - File in the PMail Directory:

Form DLL = X:\PathToDelphiCreatedDll\Demoplugin.dll

You can download the DemoPlugin Source code.

Philipp Spitzer