"No such file/directory" for each include when using POCO E-Mail

1.2k views Asked by At

This is a code for POCO Framework that should send an e-mail:

#include <iostream>
#include <Poco/Net/MailMessage.h>
#include <Poco/Net/MailRecipient.h>
#include <Poco/Net/SMTPClientSession.h>
#include <Poco/Net/NetException.h>

using namespace std;
using namespace Poco::Net;
using namespace Poco;

int main(int argc, char *argv[])
{
    string host = "mail.domain.com";
    UInt16 port = 25;
    string user = "xxx";
    string password = "xxx";
    string to = "[email protected]";
    string from = "[email protected]";
    string subject = "Your first e-mail message sent using Poco Libraries";
    subject = MailMessage::encodeWord(subject, "UTF-8");
    string content = "Well done! You've successfully sent your first message using Poco SMTPClientSession";
    MailMessage message;
    message.setSender(from);
    message.addRecipient(MailRecipient(MailRecipient::PRIMARY_RECIPIENT, to));
    message.setSubject(subject);
    message.setContentType("text/plain; charset=UTF-8");
    message.setContent(content, MailMessage::ENCODING_8BIT);
    try {
        SMTPClientSession session(host, port);
        session.open();
        try {
            session.login(SMTPClientSession::AUTH_LOGIN, user, password);
            session.sendMessage(message);
            cout << "Message successfully sent" << endl;
            session.close();
        } catch (SMTPException &e) {
            cerr << e.displayText() << endl;
            session.close();
            return 0;
        }
    } catch (NetException &e) {
        cerr << e.displayText() << endl;
        return 0;
    }
    return 0;
}

But it says for every include that there's no such file/directory. I tried putting my .cpp file in POCO folder and it did nothing. I also tried running the buildvs120.bat but I get the same error? How should I use it correctly? Please help!

1

There are 1 answers

0
Christophe On

When you indicate an #include <filename> using the brackets, your complier looks for the filename relative to the include path:

  • With MSVC you set this include path in the properties of your project. Choose C/C++ then General and enter as include directory the \dirpath of your library in such a way that \dirpath\Poco\Net is an absolute path effively pointing to the include directory where the poco headers are located.

  • With g++, you can set it with the command line option -I\dirpath.

Alternatively, you can change the #include "filename" using double quotes. In this case, the compiler looks for the filename relative to the path of the source code you are compiling.