C# Examples

ChilkatHOMEAndroid™ASPVisual BasicVB.NETC#iOS (IPhone)Objective-CC++CUnicode C++Unicode CMFCDelphi DLLDelphi ActiveXFoxProJavaPerlPHP ExtensionPHP ActiveXPythonPowerShellRubySQL ServerVBScript

C# Examples

Bounced Mail
Bz2
Character Encoding
CSV
DKIM / DomainKey
Digital Certificates
Digital Signatures
Email
Email Object
FTP
HTML Conversion
HTTP
IMAP
Encryption
MHT / HTML Email
MIME
POP3
RSA
S/MIME
SMTP
Socket
Spider
SSH
SSH Tunnel
SSH Key
SFTP
Tar Archive
Upload
XML
XMP
Zip Compression


More Examples...
Amazon S3
NTLM
FileAccess
RSS
Atom
String
Byte Array
Self-Extractor
Service
PPMD
Deflate
DH Key Exchange
DSA
Bzip2
LZW

 

 

 

 

 

 

(C#) Fetch 1st N Headers of Search Results

Calls Search to get a message set, then downloads the 1st N messages in the message set. There are two equivalent ways of doing it: (1) iterate from 0 to N-1 and download each message individually, or (2) create a new message set that contains the 1st N messages and pass it to FetchHeaders. Both are demonstrated here.

Download: Chilkat .NET Assemblies

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) {
    textBox1.Text += imap.LastErrorText + "\r\n";
    return;
}

//  Connect to an IMAP server.
success = imap.Connect("mail.chilkatsoft.com");
if (success != true) {
    textBox1.Text += imap.LastErrorText + "\r\n";
    return;
}

//  Login
success = imap.Login("****","****");
if (success != true) {
    textBox1.Text += imap.LastErrorText + "\r\n";
    return;
}

//  Select an IMAP mailbox
success = imap.SelectMailbox("Inbox");
if (success != true) {
    textBox1.Text += imap.LastErrorText + "\r\n";
    return;
}

Chilkat.MessageSet messageSet = null;
//  We can choose to fetch UIDs or sequence numbers.
bool fetchUids;
fetchUids = true;
//  Get the message IDs of all the emails in the mailbox
messageSet = imap.Search("ALL",fetchUids);
if (messageSet == null ) {
    textBox1.Text += imap.LastErrorText + "\r\n";
    return;
}

int numFound;
numFound = messageSet.Count;
if (numFound == 0) {
    textBox1.Text += "No messages found." + "\r\n";

    return;
}

//  Get the 1st 10 messages in messageSet.
int maxToGet;
maxToGet = 10;

int upperBound;
upperBound = 10;
if (numFound < upperBound) {
    upperBound = numFound;
}

int i;
bool bUid;
bUid = messageSet.HasUids;
for (i = 0; i <= upperBound - 1; i++) {

    Chilkat.Email email = null;
    email = imap.FetchSingleHeader(messageSet.GetId(i),bUid);
    if (email == null ) {
        textBox1.Text += imap.LastErrorText + "\r\n";

        return;

    }
    else {
        //  Do whatever is needed with the email..
        //  ....

    }

}

//  Alternatively, create a new message set containing the 1st 10 message id's (UID's)
//  from the search results message set:
Chilkat.MessageSet firstTen = new Chilkat.MessageSet();

for (i = 0; i <= upperBound - 1; i++) {
    firstTen.InsertId(messageSet.GetId(i),bUid);
}

//  Download the 1st ten headers:
Chilkat.EmailBundle bundle = null;
bundle = imap.FetchHeaders(firstTen);
if (bundle == null ) {

    textBox1.Text += imap.LastErrorText + "\r\n";
    return;
}

//  Other examples show how to iterate over the emails contained within the bundle...

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


 

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