Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicCkPythonChilkat2-PythonRubySQL ServerSwift 2Swift 3/4TclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcelGo

C# Examples

ASN.1
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Service Bus
Base64
Bounced Email
Box
CSR
CSV
Certificates
Compression
DKIM / DomainKey
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
ECC
Email Object
Encryption
FTP
Facebook
FileAccess
Firebase
GMail REST API
GeoOp
Google APIs
Google Calendar
Google Cloud Storage
Google Drive
Google Sheets
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)
Jira
MHT / HTML Email
MIME
Microsoft Graph
NTLM
OAuth1
OAuth2
OneDrive
OpenSSL
Outlook
PEM
PFX/P12
POP3
PRNG
PayPal
Peoplevox
QuickBooks
REST
REST Misc
RSA Encryption
SCP
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
SharePoint
Shopify
Socket/SSL/TLS
Spider
Stream
Stripe
SugarCRM
Tar Archive
Twitter
Upload
VoiceBase
Walmart
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Xero
Zip
curl
eBay

 

 

 

(C#) Download Unread Email from IMAP Mailbox

Download unread email messages from an IMAP mailbox.

Chilkat .NET Downloads

Chilkat .NET Assemblies

Chilkat for .NET Core

Chilkat for Mono

Chilkat.Imap imap = new Chilkat.Imap();

bool success;

//  Anything unlocks the component and begins a fully-functional 30-day trial.
success = imap.UnlockComponent("Anything for 30-day trial");
if (success != true) {
    Console.WriteLine(imap.LastErrorText);
    return;
}

//  Connect to an IMAP server.
//  Use TLS
imap.Ssl = true;
imap.Port = 993;
success = imap.Connect("imap.someMailServer.com");
if (success != true) {
    Console.WriteLine(imap.LastErrorText);
    return;
}

//  Login
success = imap.Login("admin@chilkatsoft.com","myPassword");
if (success != true) {
    Console.WriteLine(imap.LastErrorText);
    return;
}

//  Select an IMAP mailbox
success = imap.SelectMailbox("Inbox");
if (success != true) {
    Console.WriteLine(imap.LastErrorText);
    return;
}

Chilkat.MessageSet messageSet = null;
bool fetchUids = true;

//  Find emails marked as seen or not already seen:
string seenSearch = "SEEN";
string notSeenSearch = "NOT SEEN";

//  Get the set of unseen message UIDs
messageSet = imap.Search(notSeenSearch,fetchUids);
if (messageSet == null ) {
    Console.WriteLine(imap.LastErrorText);
    return;
}

//  Fetch the unseen emails into a bundle object:
Chilkat.EmailBundle bundle = null;
bundle = imap.FetchBundle(messageSet);
if (bundle == null ) {

    Console.WriteLine(imap.LastErrorText);
    return;
}

//  Display the Subject and From of each email.
int i;
for (i = 0; i <= bundle.MessageCount - 1; i++) {
    Chilkat.Email email = null;
    email = bundle.GetEmail(i);

    Console.WriteLine(email.GetHeaderField("Date"));
    Console.WriteLine(email.Subject);
    Console.WriteLine(email.From);
    Console.WriteLine("--");

}

//  Disconnect from the IMAP server.
success = imap.Disconnect();


 

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