Chilkat HOME ASP Visual Basic VB.NET C# Visual C++ C MFC Delphi FoxPro Java Perl PHP Python Ruby SQL Server VBScript
|
Fetch Single Email by UID or Sequence NumberAssuming the UID is known, download a single email by UID from an IMAP mail server.
#include <CkImap.h> #include <CkEmail.h> void ChilkatSample(void) { CkImap 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) { printf("%s\n",imap.lastErrorText()); return; } // Connect to an IMAP server. success = imap.Connect("mail.chilkatsoft.com"); if (success != true) { printf("%s\n",imap.lastErrorText()); return; } // Login success = imap.Login("***","***"); if (success != true) { printf("%s\n",imap.lastErrorText()); return; } // Select an IMAP mailbox success = imap.SelectMailbox("Inbox"); if (success != true) { printf("%s\n",imap.lastErrorText()); return; } CkEmail *email = 0; int uid; uid = 2014; bool isUid; isUid = true; email = imap.FetchSingle(uid,isUid); if (!(email == 0 )) { // Display the From and Subject printf("%s\n",email->fromAddress()); printf("%s\n",email->subject()); // Display the Body property, which is the default body. // If an email has an HTML body, the Body property contains // the HTML source. Otherwise it contains the plain-text // body. printf("---- EMAIL BODY ----\n"); printf("%s\n",email->body()); printf("--------------------\n"); // Display the recipients: int j; for (j = 0; j <= email->get_NumTo() - 1; j++) { printf("%s, %s\n",email->getToName(j) ,email->getToAddr(j)); } for (j = 0; j <= email->get_NumCC() - 1; j++) { printf("%s, %s\n",email->getCcName(j) ,email->getCcAddr(j)); } // Show the total size of the email, including body and attachments: printf("%d\n",email->get_Size()); // When a full email is downloaded, we would use the // email.NumAttachments property in conjunction with the // email.GetMailAttach* methods. // However, when an email object contains only the header, // we need to access the attachment info differently: int numAttach; numAttach = imap.GetMailNumAttach(*email); printf("%d\n",numAttach); for (j = 0; j <= numAttach - 1; j++) { printf("%s\n",imap.getMailAttachFilename(*email,j)); int attachSize; attachSize = imap.GetMailAttachSize(*email,j); printf(" size = %d bytes\n",attachSize); } printf("--\n"); delete email; } // Disconnect from the IMAP server. imap.Disconnect(); } |
Need a specific example? Send a request to support@chilkatsoft.com
© 2000-2008 Chilkat Software, Inc. All Rights Reserved.