Delphi Examples

ChilkatHOMEASPVisual BasicVB.NETC#Visual C++CMFCDelphiFoxProJavaPerlPHPPythonRubySQL ServerVBScript

Delphi Examples

Bounced Mail
Character Encoding
Digital Certificates
Digital Signatures
Email
FTP
HTML-to-XML
HTTP
IMAP
Encryption
MHT / HTML Email
RSA Encryption
S/MIME
Socket
Spider
String
Tar
Upload
XML
XMP
Zip Compression

More Examples...
Byte Array
Email Object
POP3
SMTP
RSS
Atom
Self-Extractor
Service
PPMD
Deflate
DH Key Exchange
DSA
SSH Key
SSH
SSH Tunnel
SFTP

Unreleased...
Bzip2
LZW
Bz2
Icon

Type Conversion

 

Article: Understanding COM References in Delphi

Advanced Email Attachments

Download Chilkat Email ActiveX

A more advanced Delphi programming example demonstrating email attachments.

// This Delphi example program provides additional details
// regarding email attachments.
procedure TForm1.Button4Click(Sender: TObject);
var
  email: IChilkatEmail2;
  bundle: IChilkatEmailBundle2;
  n: Integer;
  i: Integer;
  numAttach: Integer;
  j: Integer;
  attachSize: Integer;

begin
  // A ChilkatMailMan2 ActiveX component was dropped onto the Delphi
  // form, and this became the Form's member variable "ChilkatMailMan21".

  // Unlock the component -- only needs to be called once in a program.
  ChilkatMailMan21.UnlockComponent('Anything for 30-day trial');

  // Set the POP3 mail server hostname, login, and password.
  ChilkatMailMan21.MailHost := 'mail.chilkatsoft.com';
  ChilkatMailMan21.PopUsername := '***';
  ChilkatMailMan21.PopPassword := '***';

  // Read the entire mailbox, leaving the mail on the POP3 server.
  bundle := ChilkatMailMan21.CopyMail();
  if (bundle = nil) then
      ShowMessage(ChilkatMailMan21.LastErrorText);

  // Loop over the emails in the bundle and save any attachments
  // in the "c:/myMailAttachments" directory.
  n := bundle.MessageCount;
  for i := 0 to n-1 do begin
      email := bundle.GetEmail(i);

      // There is an email property, OverwriteExisting, that controls
      // whether the SaveAllAttachments method overwrites files that already
      // exist.  By default, OverwriteExisting equals 1, which causes
      // files to be overwritten.  Setting the property = 0 prevents
      // overwriting files.  If a file already exists, the Chilkat email
      // component will append a few random characters in the format
      // "_????" to the filename (where '?' is a random character).
      // The actual filename written is available via the GetAttachmentFilename
      // method after the attachment has been saved -- allowing your program
      // to know the attachment filename.

      email.OverwriteExisting := 0;  // Do not overwrite existing files.

      // Save all attachments to the "my_attachments" directory, which is
      // relative to the current working directory of this program.
      // If the directory does not already exist, it will be created.
      email.SaveAllAttachments('my_attachments');

      // Iterate over each attachment in an email.
      numAttach := email.NumAttachments;
      for j := 0 to numAttach-1 do begin
        // Get the size of the attachment, in bytes.
        attachSize := email.GetAttachmentSize(j);

        // Show the attachment filename.
        ListBox1.Items.Add(email.GetAttachmentFilename(j) + ' (' + IntToStr(attachSize) + ' bytes)');

        // Attachments may be saved individually.
        // Save individual .gif attachments to a separate directory.
        if AnsiEndsStr('.gif',email.GetAttachmentFilename(j)) then
            email.SaveAttachedFile(j,'gif_attachments');
     end;
  
    end;
  end;

 

 

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

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

Mail Component · .NET Email Component · XML Parser