Chilkat Examples

ChilkatHOME.NET Core C#Android™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi ActiveXDelphi DLLGoJavaLianjaMono C#Node.jsObjective-CPHP ActiveXPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

Classic ASP Examples

Web API Categories

ASN.1
AWS KMS
AWS Misc
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Key Vault
Azure Service Bus
Azure Table Service
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Code Signing
Compression
DKIM / DomainKey
DNS
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
EBICS
ECC
Ed25519
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
GMail SMTP/IMAP/POP
Geolocation
Google APIs
Google Calendar
Google Cloud SQL
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text
HTTP

HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
MS Storage Providers
Microsoft Graph
Misc
NTLM
OAuth1
OAuth2
OIDC
Office365
OneDrive
OpenSSL
Outlook
Outlook Calendar
Outlook Contact
PDF Signatures
PEM
PFX/P12
PKCS11
POP3
PRNG
REST
REST Misc
RSA
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
SharePoint
SharePoint Online
Signing in the Cloud
Socket/SSL/TLS
Spider
Stream
Tar Archive
ULID/UUID
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl
uncategorized

 

 

 

How to Process a Large IMAP Mailbox

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

Demonstrates how to process a mailbox containing a large number of emails. This example was prompted by a Chilkat customer who needed to efficiently process a mailbox with over 100,000 emails. The technique is to first select the mailbox, which updates the imap.NumMessages property to reflect the number of messages in the mailbox. The emails in the mailbox have sequence numbers ranging from 1 to NumMessages. Two new methods, FetchSequence and FetchSequenceHeaders, can then be used to fetch emails based on sequence number ranges.

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%

set imap = Server.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
    Response.Write Server.HtmlEncode(imap.LastErrorText) & "<br>"

End If

'  Connect to an IMAP server.
success = imap.Connect("mail.chilkatsoft.com")
If (success <> 1) Then
    Response.Write Server.HtmlEncode(imap.LastErrorText) & "<br>"

End If

'  Login
success = imap.Login("admin@chilkatsoft.com","*myPassword5*")
If (success <> 1) Then
    Response.Write Server.HtmlEncode(imap.LastErrorText) & "<br>"

End If

'  Our experience has been that with some IMAP servers,
'  the response time for selecting a mailbox increases with
'  the size of the mailbox.  You may need to increase the
'  ReadTimeout to a value larger than the default of 30 seconds.
'  In this case, it is set to 60 seconds.
imap.ReadTimeout = 60

'  Select an IMAP mailbox
success = imap.SelectMailbox("Inbox")
If (success <> 1) Then
    Response.Write Server.HtmlEncode(imap.LastErrorText) & "<br>"

End If

'  After selecting a mailbox, the NumMessages property will
'  be updated to reflect the total number of emails in the mailbox:
Response.Write Server.HtmlEncode(imap.NumMessages) & "<br>"

'  The emails in the mailbox will always have sequence numbers
'  ranging from 1 to NumMessages.  There are two new methods
'  that can be called to fetch emails for a range of sequence
'  numbers: FetchSequence and FetchSequenceHeaders.
'  They are identical except one returns full emails whereas
'  the other returns headers-only.

'  This example assumes there are more than 10 emails in the
'  mailbox and fetches the 1st 10 emails:

startSeqNum = 1
numToFetch = 10
Set bundle = imap.FetchSequence(startSeqNum,numToFetch)
If (bundle Is Nothing ) Then
    Response.Write Server.HtmlEncode(imap.LastErrorText) & "<br>"

End If

'  Print the From and Subject of each email:

For i = 0 To bundle.MessageCount - 1

    '  GetEmail does not communication with the IMAP server.
    '  It simply extracts a single email from the in-memory bundle.
    Set email = bundle.GetEmail(i)

    Response.Write Server.HtmlEncode(email.From) & "<br>"
    Response.Write Server.HtmlEncode(email.Subject) & "<br>"

    Response.Write Server.HtmlEncode("--") & "<br>"

Next

'  Disconnect from the IMAP server.
imap.Disconnect 


%>
</body>
</html>

 

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