Delphi - Send EML File

EML file is e-mail message saved by Microsoft Outlook Express or other e-mail programs; may also contain an e-mail attachment, or file sent with the message.

If you want to load EML file and edit it, you can use LoadMessage method to load EML file and edit it.

If you do not want to edit the EML file, and you just need to simply forward the EML file to other recipient with 100% original data, then please see the following example codes.

The following example codes demonstrate how to load EML file and forward it to specified recipient.

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 EML file using SMTP server
// 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);

  // 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();

  // Load EML file to body text temporally
  oSmtp.ImportMail( 'c:\temp\my.eml' );

  // Assign EML file data to raw content
  oSmtp.raw_Content := oSmtp.BodyText;
  ShowMessage( 'start to send email ...' );

  // Forward EML file with 100% orignal data
  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