Chilkat HOME ASP Visual Basic VB.NET C# Visual C++ C MFC Delphi FoxPro Java Perl PHP Python Ruby SQL Server VBScript
|
Read IMAP MailboxBasic Delphi example program showing how to connect to an IMAP server, login, select a mailbox, and fetch the emails one by one. procedure TForm1.Button1Click(Sender: TObject);
var
connectSuccess: Integer;
loginSuccess: Integer;
selectSuccess: Integer;
mset: IMessageSet;
n: Integer;
i: Integer;
email: IChilkatEmail2;
begin
loginSuccess := 0;
selectSuccess := 0;
// Import the Chilkat IMAP ActiveX and drop an instance
// of ChilkatImap onto your Delphi program's form.
ChilkatImap1.UnlockComponent('anything for 30-day trial');
// -------------------------
// Connect to an IMAP server.
// -------------------------
connectSuccess := ChilkatImap1.Connect('myImapServerHostname');
if (connectSuccess = 0) then
begin
ShowMessage('Failed to connect!');
ChilkatImap1.SaveLastError('connectErrorLog.txt');
end;
// -------------------------
// IMAP Login
// -------------------------
if (connectSuccess = 1) then
loginSuccess := ChilkatImap1.Login('myLogin', 'myPassword');
if (loginSuccess = 0) then
begin
ShowMessage('Failed to login!');
ChilkatImap1.SaveLastError('loginErrorLog.txt');
end;
// -------------------------
// Select an IMAP Mailbox
// -------------------------
if (loginSuccess = 1) then
selectSuccess := ChilkatImap1.SelectMailbox('INBOX');
if (selectSuccess = 0) then
begin
ShowMessage('Failed to select mailbox!');
ChilkatImap1.SaveLastError('selectErrorLog.txt');
end;
if (selectSuccess = 1) then
begin
// -------------------------
// Fetch the complete set of UIDs for the mail in the selected mailbox.
// -------------------------
mset := ChilkatImap1.GetAllUids();
if (mset = nil) then
begin
ShowMessage('Failed to fetch Uids');
ChilkatImap1.SaveLastError('getUidsErrorLog.txt');
end
else
begin
// For each UID, fetch the email and display the FROM and Subject
n := mset.Count;
for i := 0 to n-1 do
begin
email := ChilkatImap1.FetchSingle(mset.GetID(i),1);
if (email <> nil) then
begin
Memo1.Lines.Add(email.From);
Memo1.Lines.Add(email.Subject);
Memo1.Lines.Add('----');
end;
end;
end;
end;
ShowMessage('Finished!');
end;
|
Need a specific example? Send a request to support@chilkatsoft.com
© 2000-2008 Chilkat Software, Inc. All Rights Reserved.