How to invoke the default mailer program to send an email?

Invoking the default mailer program to send an email

Copyright © 2000 Ernesto De Spirito

Storage Library - Save your app's configuration

You can invoke the "New Message" or "Compose Message" window of the default mailer program using the API function ShellExecute declared in the ShellApi unit, passing 'mailto:' as the third parameter (lpFile), as shown below:

uses ShellAPI;

procedure TForm1.Button1Click(Sender: TObject);
begin
  ShellExecute(Self.Handle, nil, 'mailto:', nil, nil, SW_NORMAL);
end;

You can also add the email address of the recipient:

procedure TForm1.Button1Click(Sender: TObject);
begin
  ShellExecute(Self.Handle, nil,
    'mailto:eds2009 @ latiumsoftware.com',
    nil, nil, SW_NORMAL);
end;

The subject line can be also be included:

procedure TForm1.Button1Click(Sender: TObject);
begin
  ShellExecute(Self.Handle, nil,
    'mailto:eds2009 @ latiumsoftware.com?Subject=Test',
    nil, nil, SW_NORMAL);
end;

And even the body of the message:

procedure TForm1.Button1Click(Sender: TObject);
begin
  ShellExecute(Self.Handle, nil,
    'mailto:eds2009 @ latiumsoftware.com' +
    '?Subject=Test&Body=Just testing the example',
    nil, nil, SW_NORMAL);
end;

 
NOTE: The mailto protocol does not support attachments.

JfControls Library - for Delphi and C++ Builder