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! ;)
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.