Delphi DLL
Delphi DLL
Download POP3 Email using UIDLs
Demonstrates how to download POP3 email by first getting the complete set of UIDLs and then downloading email by calling FetchByUIDL for each UIDL.Chilkat Delphi DLL Downloads
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, StringTable, Email, MailMan;
...
procedure TForm1.Button1Click(Sender: TObject);
var
success: Boolean;
mailman: HCkMailMan;
stUidls: HCkStringTable;
email: HCkEmail;
count: Integer;
i: Integer;
begin
success := False;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
// The mailman object is used for receiving (POP3)
// and sending (SMTP) email.
mailman := CkMailMan_Create();
// Set the POP3 server's hostname
CkMailMan_putMailHost(mailman,'pop.example.com');
// Set the POP3 login/password.
CkMailMan_putPopUsername(mailman,'myLogin');
CkMailMan_putPopPassword(mailman,'myPassword');
stUidls := CkStringTable_Create();
success := CkMailMan_FetchUidls(mailman,stUidls);
if (success = False) then
begin
Memo1.Lines.Add(CkMailMan__lastErrorText(mailman));
Exit;
end;
email := CkEmail_Create();
count := CkStringTable_getCount(stUidls);
i := 0;
while i < count do
begin
// Download the full email.
success := CkMailMan_FetchByUidl(mailman,CkStringTable__stringAt(stUidls,i),False,0,email);
if (success = False) then
begin
Memo1.Lines.Add(CkMailMan__lastErrorText(mailman));
Exit;
end;
Memo1.Lines.Add(IntToStr(i));
Memo1.Lines.Add('From: ' + CkEmail__from(email));
Memo1.Lines.Add('Subject: ' + CkEmail__subject(email));
i := i + 1;
end;
CkMailMan_Pop3EndSession(mailman);
CkMailMan_Dispose(mailman);
CkStringTable_Dispose(stUidls);
CkEmail_Dispose(email);
end;