EASendMail SMTP Component > Developer Center > Example Codes > Delphi > Send Email using MX DNS lookup - Smart Host

Delphi - Send Email using MX DNS lookup - Smart Host

In general, we send email via specified SMTP server. How does the specified SMTP server know what address this email should be sent to? The answer is... it queries MX record of recipient's domain via DNS lookup. It then forwards this email to the SMTP server queried from DNS server. If recipient's server doesn't work fine, sender's SMTP server will send a failure-delivery report to the sender telling it failed to send out the email.

How does EASendMail SMTP component work with "Send email directly"? Firstly, it queries MX record for recipient address from DNS, then sends email to recipient's email server directly. In short, if no SMTP server is specified in the code, EASendMail will send email to recipient directly. Since querying DNS server consumes CPU time and networking resource, the performance of "Send email directly" is lower than sending email with specified SMTP server. Moreover, nowadays more and more SMTP servers block email sent from dynamic IP address, so we don't recommend you to use "Direct Send Email" except you have a static IP address or you encounter problem with your ISP SMTP server.

Every recipient may have different SMTP server, if there are multiple recipients in one message and you want to send email directly, you should send the email to the recipients one by one.

To implement this feature, you just need to put nothing to SMTP server address.

The following example codes demonstrate how to send email without specified 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 using MX DNS lookup
// 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';

  // Do not set SMTP server address
  oSmtp.ServerAddr := '';

  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