IOS / Objective-C: library for connecting to POP3

I would like to connect to IMAP and POP3 servers, for IMAP I am currently using MailCore. Unfortunately, I did not find a suitable POP3 wireframe.

I tried with libetpan:

mailpop3 * pop3; int r; pop3 = mailpop3_new(0, NULL); r = mailpop3_ssl_connect(pop3, "pop.gmail.com", 995); check_error(r, "connect failed"); 

but I always get a failure error message; and this is only C, I would prefer Objective-C. Even better would be a library that I could use for both; IMAP and POP3.

+4
source share
2 answers

I have not used OCMail , but it seems to be what you are looking for. He claims to support "POP3, IMAP4, SMTP, POPS, IMAPS, SMTPS."

Edit: create error
Turns out the solution is really in the README file.

  • Once you have downloaded the ZIP from Github, open the Xcode project.
  • Create profiling (product menu> build> profiling (Command-Shift-I)).
  • Open the Xcode settings and go to the "Locations" section.
  • In the "Derived Data" section next to the "Advanced" button, you will see the path to the file (something like /Users/YourUserName/Library/Developer/Xcode/DerivedData ). There will be a small arrow next to the track; click the arrow to go to this place in the Finder.
  • This will lead you to the folder with all your Xcode projects. Find the folder whose name begins with OCMail (and after it there is a bunch of gibberish).
  • In this folder, find Build> Products> Debug-iphoneos> libOCMail.a . This is the library file that you want to add to your Xcode project. Just drag it into your Xcode project and you should be good to go.

I had a lot of errors when creating a project. They came from a poorly defined type of enum . Here is the cleaned file: http://cl.ly/code/442x2x3X3Y2I
Just download and replace the existing MimeMessage.m file before creating it.

+3
source

I worked with libetpan in the past, and I connected to the pop3 server without any problems, so I checked if everything works. I used the code here: https://github.com/dinhviethoa/libetpan/blob/master/tests/pop-sample.c and adjusted it for iOS.

If you use it, you will see a lot of warnings, and the application will crash after receiving the first message, but the connection works (of course, you need to enter your email address and password).

I am not saying libetpan is a good solution. When I was developing a mail-enabled application, I also used mailcore for IMAP and eventually dropped POP3 support. But if you run from the options, this may be useful.

 static void check_error(int r, char * msg) { if (r == MAILPOP3_NO_ERROR) return; fprintf(stderr, "%s\n", msg); exit(EXIT_FAILURE); } -(IBAction)testButtonClick:(id)sender { mailpop3 * pop3; int r; carray * list; unsigned int i; // if (argc < 3) { // fprintf(stderr, "syntax: pop-sample [gmail-email-address] [gmail- password]\n"); // exit(EXIT_FAILURE); // } mkdir("download", 0700); pop3 = mailpop3_new(0, NULL); r = mailpop3_ssl_connect(pop3, "pop.gmail.com", 995); check_error(r, "connect failed"); r = mailpop3_user(pop3, @"mail login".cString); check_error(r, "user failed"); r = mailpop3_pass(pop3, @"mail password".cString); check_error(r, "pass failed"); r = mailpop3_list(pop3, &list); check_error(r, "list failed"); NSLog(@"carray_count(list_: %d", carray_count(list)); for(i = 0 ; i < carray_count(list) ; i ++) { struct mailpop3_msg_info * info; char * msg_content; size_t msg_size; FILE * f; char filename[512]; struct stat stat_info; info = (mailpop3_msg_info *) carray_get(list, i); if (info->msg_uidl == NULL) { continue; } snprintf(filename, sizeof(filename), "download/%s.eml", info->msg_uidl); r = stat(filename, &stat_info); if (r == 0) { printf("already fetched %u %s\n", info->msg_index, info->msg_uidl); continue; } if(msg_content != NULL) NSLog(@"msg_content: %@", [NSString stringWithUTF8String:msg_content]); r = mailpop3_retr(pop3, info->msg_index, &msg_content, &msg_size); check_error(r, "get failed"); // f = fopen(filename, "w"); // fwrite(msg_content, 1, msg_size, f); // fclose(f); // mailpop3_retr_free(msg_content); if (info->msg_uidl != NULL) { printf("fetched %u %s\n", info->msg_index, info->msg_uidl); } else { printf("fetched %u\n", info->msg_index); } } mailpop3_quit(pop3); mailpop3_free(pop3); // exit(EXIT_SUCCESS); } 
+1
source

All Articles