How to use POCO C++ library to receive emails and analyse contents

I've one task to do, and that is:
  • Get emails from accounts, account info (username, password, saveBody, saveAttachments) can be obtained from EmailInboundConfig object
  • Retrieve subject, each attachment's filename

After comparing 3 open source C++ email handling libraries, I've decided to give POCO library a go.  Remember to include the following in the header (*.h) files.

#include "Poco/Net/POP3ClientSession.h"
#include "Poco/Net/MailMessage.h"
#include "Poco/Net/PartHandler.h"
#include "Poco/Net/MessageHeader.h"
#include "Poco/Net/NameValueCollection.h"
#include "Poco/Net/QuotedPrintableDecoder.h"
#include "Poco/Net/MultipartReader.h"
#include "Poco/Exception.h"
#include "Poco/StreamCopier.h"
#include "Poco/Base64Decoder.h"
#include <iostream>
#include <fstream>


17 comments:

  1. Hi, Which library do you include to use String::TakeField method ?

    ReplyDelete
  2. Hi @MaKay, it's actually a custom function. I've just included it in the post.

    ReplyDelete
  3. Thanks your reply, JustinW. What is the functionality of String::FixField method ? Or can you post all source of custom String class ?

    ReplyDelete
  4. Thanks the source of String class, JustinW. Currently I've read Service.cpp file, I see that you used 2 methods: MyMailMessage::write() and MyMailMessage::isMultipart(), I don't understand internally the purpose of these methods. Can you post the source of MyMailMessage class ?

    ReplyDelete
  5. Hi @MaKay, sorry for the confusion. MyMailMessage class is actually an extension of the POCO library class, MailMessage. I will include MyMailMessage header file for you to refer.

    ReplyDelete
  6. It clear me now, thanks JustinW.

    ReplyDelete
  7. In ProcessEmail member function of Service class, you haven't saved file attachments to somewhere in local, have you? And if email's file attachments are binary format (word, excel, pdf), how can you save them ?

    ReplyDelete
  8. File::Copy(outputBodyPath,creatorFilePath) will copy any attachment found in email to local server file directory.

    ReplyDelete
  9. Could you please add MyPartHandler.h also!?

    ReplyDelete
  10. Didn't you have this problem? https://github.com/pocoproject/poco/issues/160

    ReplyDelete
    Replies
    1. Hi Jochen,

      Sorry, I haven't encountered this issue before. Which email client software are you using? As I know, there're a few different email standards out there that we need to deal with. I've been testing it using Outlook Express, Yahoo and Gmail.

      Delete
  11. Hi, can you post Directory.h, too please - and Dircetory.cpp if there is one - this is looking like an awesome piece of code. Thanks!

    ReplyDelete
    Replies
    1. Hi tumnus,

      It's my mistake to include Directory headers in there, I don't think any function is using Directory class. Please correct me if I'm wrong.

      Delete
  12. This comment has been removed by the author.

    ReplyDelete
  13. Hi, kannst Du kurz erklären, wom man die Dateien für #include iconv.h" herbekommt?
    Auf Win7 und VS2010 ist nichts dazu zu finden
    THX.

    ReplyDelete
  14. Jammin' Jars Casino and Resort - KTH
    JAMMIN' JARS is a hotel and casino located in 경주 출장마사지 Las Vegas, Nevada. The Jammin Jars Casino & Resort 서산 출장샵 is located 인천광역 출장안마 in 과천 출장마사지 the 경상남도 출장마사지 center of the Las Vegas Strip, a

    ReplyDelete