Objective-C Requires Chilkat v11.0.0+
Objective-C
Preview POP3 messages and download a complete email
See more Email Object Examples
Read a short preview for each of up to five messages into an EmailBundle, print their subjects, and download the complete first entry into a separate Email. Configure a POP3 account that supports UIDL and TOP. All messages stay on the server.
Chilkat Objective-C Downloads
#import <CkoMailMan.h>
#import <CkoEmailBundle.h>
#import <CkoEmail.h>
BOOL success = NO;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
CkoMailMan *mail = [[CkoMailMan alloc] init];
mail.MailHost = @"pop.example.com";
mail.MailPort = [NSNumber numberWithInt:995];
mail.PopSsl = YES;
mail.RequireSslCertVerify = YES;
mail.PopUsername = @"MAIL_USER";
mail.PopPassword = @"MAIL_PASSWORD";
CkoEmailBundle *previews = [[CkoEmailBundle alloc] init];
// Keep the messages and request minimal previews. Range indexes are zero-based and inclusive.
success = [mail FetchRange: YES headersOnly: YES numBodyLines: [NSNumber numberWithInt: 0] startIndex: [NSNumber numberWithInt: 0] endIndex: [NSNumber numberWithInt: 4] bundle: previews];
if (success != YES) {
NSLog(@"%@",mail.LastErrorText);
return;
}
if ([previews.MessageCount intValue] == 0) {
NSLog(@"%@",@"There are no messages to preview.");
success = [mail Pop3EndSession];
if (success != YES) {
NSLog(@"%@",mail.LastErrorText);
return;
}
return;
}
CkoEmail *header = [[CkoEmail alloc] init];
int i = 0;
while ((i < [previews.MessageCount intValue])) {
success = [previews EmailAt: [NSNumber numberWithInt: i] email: header];
if (success != YES) {
NSLog(@"%@",previews.LastErrorText);
return;
}
NSLog(@"%@%@%@",header.Uidl,@" ",header.Subject);
i = i + 1;
}
// A UI could use its selected row here. FetchFull uses the preview's POP3 identity.
success = [previews EmailAt: [NSNumber numberWithInt: 0] email: header];
if (success != YES) {
NSLog(@"%@",previews.LastErrorText);
return;
}
CkoEmail *email = [[CkoEmail alloc] init];
success = [mail FetchFull: header fullEmail: email];
if (success != YES) {
NSLog(@"%@",mail.LastErrorText);
return;
}
success = [mail Pop3EndSession];
if (success != YES) {
NSLog(@"%@",mail.LastErrorText);
return;
}
NSLog(@"%@%@%@%d",@"Full message: ",email.Subject,@" Files: ",[email.NumAttachments intValue]);
success = [email SaveEml: @"pop-received.eml"];
if (success != YES) {
NSLog(@"%@",email.LastErrorText);
return;
}
NSLog(@"%@",@"Saved pop-received.eml.");