TSendMail (C++)

From RAD Studio Code Examples
Jump to: navigation, search


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

To create the project

  • Create a C++Builder VCL Forms Application.
  • Drag and drop on the main form (Form1) a button (TButton), a file open dialog (TOpenDialog), and an action list (TActionList).
  • Add a TSendMail action:
  • 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.


void __fastcall TForm1::Button1Click(TObject *Sender) {
	if (OpenDialog1->Execute()) {
		if (FileExists(OpenDialog1->FileName, false)) {
		else {
			throw new Exception("No such file");


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).


See Also