I don't know why i get this error message:
terminate called after throwing an instance of 'Poco::Net::SSLException'
what(): SSL Exception
This is the relevant part of my code:
#include <Poco/Net/SecureSMTPClientSession.h>
#include <Poco/Net/InvalidCertificateHandler.h>
#include <Poco/Net/AcceptCertificateHandler.h>
#include <Poco/Net/SSLManager.h>
#include <Poco/Net/SecureStreamSocket.h>
#include <Poco/Net/StringPartSource.h>
#include <Poco/Net/MailMessage.h>
#include <Poco/Net/Context.h>
#include <Poco/Net/SocketAddress.h>
#include <Poco/Net/SMTPClientSession.h>
#include <string>
#include "smtp.h"
using namespace Poco::Net;
using namespace Poco;
using namespace std;
SMTP::SMTP()
{
MailMessage mailMessage;
mailMessage.addRecipient(MailRecipient(MailRecipient::PRIMARY_RECIPIENT, "test", "test"));
mailMessage.setSubject("test");
mailMessage.setSender("test");
mailMessage.setContent("Test\r\n");
string sSmtpServer = "smtp.gmail.com";
UInt16 nSmtpPort = 587;
string sUserName = "test";
string sPassword = "test";
initializeSSL();
SharedPtr<InvalidCertificateHandler> pCert = new AcceptCertificateHandler(false);
Context::Ptr pContext = new Poco::Net::Context(Context::CLIENT_USE, "", "", "", Context::VERIFY_NONE, 9, false, "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
SSLManager::instance().initializeClient(0, pCert, pContext);
SecureStreamSocket* pSSLSocket = new SecureStreamSocket(pContext);
pSSLSocket->connect(SocketAddress(sSmtpServer, nSmtpPort));
Poco::Net::SecureSMTPClientSession* pSecure = new SecureSMTPClientSession(*pSSLSocket);
pSecure->open();
pSecure->login();
if (!pSecure->startTLS(pContext))
throw std::string("Failed to start TLS connection.");
pSecure->login(SMTPClientSession::AUTH_LOGIN, sUserName, sPassword);
pSecure->sendMessage(mailMessage);
pSecure->close();
}
The exception happens at the line:
pSSLSocket->connect(SocketAddress(sSmtpServer, nSmtpPort));
The SMTP constructor is called from another object. I wonder how I could troubleshoot the exception more clearly, I am using Qt Creator.
Any ideas? Thanks.