Chilkat HOME Android™ Classic ASP C C++ C# Mono C# .NET Core C# C# UWP/WinRT DataFlex Delphi ActiveX Delphi DLL Visual FoxPro Java Lianja MFC Objective-C Perl PHP ActiveX PHP Extension PowerBuilder PowerShell PureBasic CkPython Chilkat2-Python Ruby SQL Server Swift 2 Swift 3/4 Tcl Unicode C Unicode C++ Visual Basic 6.0 VB.NET VB.NET UWP/WinRT VBScript Xojo Plugin Node.js Excel Go
(VBScript) Fetch Oldest/Newest IMAP EmailEmails may be downloaded by sequence number. Assuming the selected mailbox is not empty, the oldest email is at sequence number 1, and the newest email is at sequence number N. The FetchSingle method may be used to download by sequence number.
Dim fso, outFile Set fso = CreateObject("Scripting.FileSystemObject") Set outFile = fso.CreateTextFile("output.txt", True) set imap = CreateObject("Chilkat_9_5_0.Imap") ' Anything unlocks the component and begins a fully-functional 30-day trial. success = imap.UnlockComponent("Anything for 30-day trial") If (success <> 1) Then outFile.WriteLine(imap.LastErrorText) WScript.Quit End If ' Connect to an IMAP server. ' Use TLS imap.Ssl = 1 imap.Port = 993 success = imap.Connect("mail.testemail.net") If (success <> 1) Then outFile.WriteLine(imap.LastErrorText) WScript.Quit End If ' Login success = imap.Login("***","***") If (success <> 1) Then outFile.WriteLine(imap.LastErrorText) WScript.Quit End If ' Select an IMAP mailbox success = imap.SelectMailbox("Inbox") If (success <> 1) Then outFile.WriteLine(imap.LastErrorText) WScript.Quit End If ' After selecting a mailbox, the NumMessages property ' contains the number of emails in the selected mailbox. n = imap.NumMessages If (n > 0) Then ' The oldest email is always at sequence number 1. isUid = 0 ' oldestEmail is a Chilkat_9_5_0.Email Set oldestEmail = imap.FetchSingle(1,isUid) If (Not (oldestEmail Is Nothing )) Then ' Display the From and Subject outFile.WriteLine(oldestEmail.FromAddress) outFile.WriteLine(oldestEmail.Subject) outFile.WriteLine("--") End If ' The newest email is at sequence number N: ' newestEmail is a Chilkat_9_5_0.Email Set newestEmail = imap.FetchSingle(n,isUid) If (Not (newestEmail Is Nothing )) Then ' Display the From and Subject outFile.WriteLine(newestEmail.FromAddress) outFile.WriteLine(newestEmail.Subject) End If End If ' Disconnect from the IMAP server. success = imap.Disconnect() outFile.Close |
© 2000-2016 Chilkat Software, Inc. All Rights Reserved.