Delphi Examples

ChilkatHOMEASPVisual BasicVB.NETC#Visual C++CMFCDelphiFoxProJavaPerlPHPPythonRubySQL ServerVBScript

Delphi Examples

Bounced Mail
Bz2
Character Encoding
CSV
DKIM / DomainKey
Digital Certificates
Digital Signatures
DH Key Exchange
DSA
Email
Email Object
FTP
HTML-to-XML
HTTP
IMAP
Encryption
MHT / HTML Email
NTLM
POP3
RSA
S/MIME
SMTP
Socket
Spider
SFTP
SSH
SSH Key
SSH Tunnel
String
Tar
Upload
XML
XMP
Zip Compression

More Examples...
Byte Array
FileAccess
RSS
Atom
Self-Extractor
Service
PPMD
Deflate
Bzip2
LZW

Type Conversion

 

Article: Understanding COM References in Delphi

Load MIME (or S/MIME) and Send as Email

Demonstrates how to load a MIME file and send it as email.

Download Chilkat Email ActiveX

Download Chilkat IMAP ActiveX

uses
    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    Dialogs, StdCtrls,
    CHILKATMAILLib2_TLB,
    CHILKATMIMELib_TLB,
    OleCtrls;

...

procedure TForm1.Button1Click(Sender: TObject);
var
mime: CHILKATMIMELib_TLB.IChilkatMime;
mailman: TChilkatMailMan2;
success: Integer;
fromAddr: String;
recipient: String;
email: CHILKATMAILLib2_TLB.IChilkatEmail2;
dateStr: String;
mimeContent: String;

begin
mime := CoChilkatMime.Create();
mailman := TChilkatMailMan2.Create(Self);

//  Any string argument automatically begins the 30-day trial.
success := mime.UnlockComponent('30-day trial');
if (success <> 1) then
  begin
    ShowMessage(mime.LastErrorText);
    Exit;
  end;

//  Any string argument automatically begins the 30-day trial.
success := mailman.UnlockComponent('30-day trial');
if (success <> 1) then
  begin
    ShowMessage(mailman.LastErrorText);
    Exit;
  end;

//  Set the SMTP server.
mailman.SmtpHost := 'smtp.chilkatsoft.com';

//  Set the SMTP login/password (if required)
mailman.SmtpUsername := 'myUsername';
mailman.SmtpPassword := 'myPassword';

//  Load the MIME (or S/MIME) from a file:
success := mime.LoadMimeFile('edifact_smime.txt');
if (success <> 1) then
  begin
    ShowMessage(mime.LastErrorText);
    Exit;
  end;

fromAddr := 'admin@chilkatsoft.com';
recipient := 'support@chilkatsoft.com';

//  Add email header fields to the MIME:
mime.AddHeaderField('From',fromAddr);
mime.AddHeaderField('To',recipient);
mime.AddHeaderField('Subject','Here is my EDIFACT signed and encrypted...');

//  We want a Date header with the current date/time.  The email object
//  automatically generates it.  Therefore we'll create an email object and then
//  copy the Date header:
email := CoChilkatEmail2.Create();
dateStr := email.GetHeaderField('Date');
mime.AddHeaderField('Date',dateStr);

//  It is not necessary to save the MIME to a file.
//  We're doing it here just to have a look at the .eml in a text editor...
success := mime.SaveMime('email.eml');
if (success <> 1) then
  begin
    ShowMessage(mime.LastErrorText);
    Exit;
  end;

//  Now send the MIME via SMTP:
mimeContent := mime.GetMime();
success := mailman.SendMime(fromAddr,recipient,mimeContent);
if (success <> 1) then
  begin
    ShowMessage(mailman.LastErrorText);
    Exit;
  end;

success := mailman.CloseSmtpConnection();
if (success <> 1) then
  begin
    ShowMessage('Connection to SMTP server not closed cleanly.');
  end;

ShowMessage('Mail Sent!');
end;

 

Need a specific example? Send a request to support@chilkatsoft.com

© 2000-2010 Chilkat Software, Inc. All Rights Reserved.

Mail Component · .NET Email Component · XML Parser