TSendMail (Delphi)

From RAD Studio Code Examples
Jump to: navigation, search

Description

This example shows how to use a TSendMail action to send an e-mail with a file attached.

To create the project

  • Right-click the action list object and select Action List Editor....
  • Select New Standard Action (Ctrl+Ins).
  • From the Internet action class, select TSendMail.
  • Write the following code in the button's Onclick event.

Code

procedure TForm1.Button1Click(Sender: TObject);
begin
  if OpenDialog1.Execute then
    if FileExists(OpenDialog1.FileName) then
    begin
      SendMail1.Attachments.Add(OpenDialog1.FileName);
      SendMail1.Execute;
    end
    else
      raise Exception.Create('No such file');
end;

Result

When the button (Button1) is pressed, the file open dialog (OpenDialog1) is shown. The user must select a file. When the Open button is pressed, the selected file is added as an attachment to the e-mail and the e-mail is shown for editing (with the help of any e-mail application available on the computer).

Uses

See Also