EASendMail SMTP Component > Developer Center > Example Codes > Delphi > Send Email using SMTP Server

Delphi - Send Email using SMTP Server

The following example codes demonstrate how to compose a simple text email and send it using SMTP server.

Installation

Before you can use the following sample codes, you should download the EASendMail Installer and install it on your machine at first.

Add Reference of EASendMail ActiveX Object to Delphi Project

To use EASendMail SMTP ActiveX Object in your project, the first step is "Add reference of EASendMail to your project". Please choose menu->"Project" -> "Import Type Library"- > and choose the "EASendMailObj ActiveX Object", click "Create Unit", the reference of EASendMail ActiveX Object will be added to your project, and you can start to use EASendMail to send email in your Delphi project.

add reference in Delphi



// The following example codes demonstrate sending email message with simple text/plain body format
// To get full sample projects, please download and install EASendMail on your machine.
// To run it correctly, please change SMTP server, user, password, sender, recipient value to yours

Unit Unit1;

Interface

Uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, EASendMailObjLib_TLB; // add EASendMail Unit

Type
  TForm1 = Class(TForm)
    Button1: TButton;
    Procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  End;

Var
  Form1: TForm1;

Implementation

{$R *.dfm}

Procedure TForm1.Button1Click(Sender: TObject);
Var
  oSmtp : TMail;
Begin
  oSmtp := TMail.Create(Application);
  oSmtp.LicenseCode := 'TryIt';

  // Set your sender email address
  oSmtp.FromAddr := 'test@emailarchitect.net';

  // Add recipient email address
  oSmtp.AddRecipientEx( 'support@emailarchitect.net', 0);

  // Set email subject
  oSmtp.Subject := 'simple email from Delphi project';

  // Set email body
  oSmtp.BodyText := 'this is a test email sent from Delphi project, do not reply';

  // Your SMTP server address
  oSmtp.ServerAddr := 'smtp.emailarchitect.net';

  // User and password for ESMTP authentication, if your server doesn't require
  // user authentication, please remove the following codes
  oSmtp.UserName := 'test@emailarchitect.net';
  oSmtp.Password := 'testpassword';

  // If your SMTP server requires SSL connection, please add this line
  // oSmtp.SSL_init();

  ShowMessage( 'start to send email ...' );

  If oSmtp.SendMail() = 0 Then
    ShowMessage( 'email was sent successfully!' )
  Else
    ShowMessage( 'failed to send email with the following error: '
    + oSmtp.GetLastErrDescription());

End;

End.

Comments

If you have any comments or questions about above example codes, please click here to add your comments.

Free Email Support

Not enough? Please contact our technical support team.

Support@EmailArchitect.NET

Remarks
We usually reply emails in 24hours. The reason for getting no response is likely that your smtp server bounced our reply. In this case, please try to use another email address to contact us. Your Gmail, Hotmail or Yahoo email account is recommended.

Related Links

Send Email - C# - VB6 - Visual Basic - VC++ - Managed C++ - Delphi

Retrieve Email and Parse Email - C# - VB6 - Visual Basic - VC++ - Managed C++ - Delphi

Email Solution - Email Server - DomainKeys/DKIM - Disclaimer

2003 - 2011 © Copyright AdminSystem Software Limited. All rights reserved.   About us     Follow emailarchitect on Twitter