0

I recently started to use POCO C++ libraries to create a simple mail client and I needed to use SecureSMTPClientSession class, but compiler reports

Poco/Net/SecureSMTPClientSession.h: No such file or directory

When I searched trough installed libraries I noticed that NETSSL_OPENSSL missing although it exists in originally downloaded file from pocoproject.org.

My installation steps followed INSTALL instructions

./configure
make
make install

So is there a way to manually install NETSSL_OPENSSL library?

Please if anybody knew to write a steps.

Thank you.

2
  • I wich folder is the library installed?
    – A.B.
    May 17, 2015 at 15:52
  • Really? make install? In 2015? When the POCO is already bundled in Ubuntu? I'd recommend you to remove everything you download and install from repository.
    – user98829
    May 17, 2015 at 15:52

2 Answers 2

0

I think you did the same like I did before... I was checking the newest Poco doc and was using an older version... It was not obvious for the first but after a while I realized...

Based on this site: [ http://axistasoft.com/blog/poco/poco-net/item/sending-email-messages-using-poco-securestreamsocket-securesmtpclientsession-class ] I think I managed to create a code for sending SMTP over SSL (I could not test it because I realized that the SMTP server is NOT SSL forced while the system administrator told me it is...)

So the code:

#include <Poco/Crypto/OpenSSLInitializer.h>
#include <Poco/Net/MailMessage.h>
#include <Poco/Net/MailRecipient.h>
#include <Poco/Net/SecureStreamSocket.h>
#include <Poco/Net/SMTPClientSession.h>
#include <Poco/Net/NetException.h>
#include <Poco/Net/Context.h>
#include <Poco/Net/SSLManager.h>
#include <Poco/Net/AcceptCertificateHandler.h>
#include <Poco/AutoPtr.h>

void sendMail() {
    using Poco::Net::MailMessage;
    using Poco::Net::MailRecipient;
    using Poco::Net::InvalidCertificateHandler;
    using Poco::Net::AcceptCertificateHandler;
    using Poco::Net::Context;
    using Poco::Net::SSLManager;
    using Poco::Net::SocketAddress;
    using Poco::Net::SecureStreamSocket;
    using Poco::Net::StreamSocket;
    using Poco::Net::SMTPClientSession;
    using Poco::Net::SMTPException;
    using Poco::Net::NetException;
    using Poco::Crypto::OpenSSLInitializer;
    using Poco::SharedPtr;

    std::string host = "smtp_host.com";
    int port = 465;
    std::string user = "smtp-user";
    std::string password = "smtp-password";
    std::string to = "[email protected]";
    std::string from = "[email protected]";
    std::string subject = "This is the subject";
    subject = Poco::Net::MailMessage::encodeWord(subject, "UTF-8");
    std::string content = "This is the message body";

    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 {
        OpenSSLInitializer::initialize();
        SharedPtr<InvalidCertificateHandler> ptrHandler = new AcceptCertificateHandler(false);
        Context::Ptr ptrContext = new Context(Context::CLIENT_USE, "", "", "", Context::VERIFY_RELAXED, 9, true, "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
        SSLManager::instance().initializeClient(0, ptrHandler, ptrContext);

        SocketAddress sa(host, port);
        SecureStreamSocket socket(sa);
        SMTPClientSession session(socket);

        try {
            session.login(SMTPClientSession::AUTH_LOGIN, user, password);
            session.sendMessage(message);
            session.close();
            OpenSSLInitializer::uninitialize();
        } catch (SMTPException &e) {
            _errorOccurred(e.displayText());
            session.close();
            OpenSSLInitializer::uninitialize();
            return;
        }
    } catch (NetException &e) {
        _errorOccurred(e.displayText());
        return;
    }
}

I hope you can use it :) Let's send hugs and kisses to http://axistasoft.com to Singapore :)

Good luck! ;)

0

From the link https://pocoproject.org/releases/poco-1.7.6/ download the poco-1.7.6-all.zip not poco-1.7.6.zip because poco-1.7.6-all.zip will have all components while poco-1.7.6.zip does not contain all components.

SecureSMTPClientSession.h is well present in poco-1.7.6-all.zip.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .