when I was searching for a smtp class I found a link to the poco project site. After I managed to compile the whole library I tried to run the mail sample. It didn't work because of the starttls command. I searched the forum and asked google for help. I found some topics and sites, but despite I rtfm the sources, I still cant accomplish the simple task sending an email.
Of course i changed the sample code but when I run the program it throws an exception:
- Code: Select all
#include "Poco/Net/MailMessage.h"
#include "Poco/Net/MailRecipient.h"
#include "Poco/Net/SMTPClientSession.h"
#include "Poco/Net/StringPartSource.h"
//new code
#include "Poco/Net/SocketAddress.h"
#include "Poco/Net/StreamSocket.h"
#include "Poco/Net/DialogSocket.h"
#include "Poco/Net/SecureStreamSocket.h"
// end new code
#include "Poco/Path.h"
#include "Poco/Exception.h"
#include <iostream>
using Poco::Net::MailMessage;
using Poco::Net::MailRecipient;
using Poco::Net::SMTPClientSession;
using Poco::Net::StringPartSource;
// new code
using Poco::Net::SocketAddress;
using Poco::Net::StreamSocket;
using Poco::Net::DialogSocket;
using Poco::Net::SecureStreamSocket;
// end new code
using Poco::Path;
using Poco::Exception;
const unsigned char PocoLogo[] =
{
#include "PocoLogo.hpp"
};
int main(int argc, char** argv)
{
if (argc != 4)
{
Path p(argv[0]);
std::cerr << "usage: " << p.getBaseName() << " <mailhost> <sender> <recipient>" << std::endl;
std::cerr << " Send an email greeting from <sender> to <recipient>," << std::endl;
std::cerr << " the SMTP server at <mailhost>." << std::endl;
return 1;
}
std::string mailhost(argv[1]);
std::string sender(argv[2]);
std::string recipient(argv[3]);
// new
std::string port("25");
try
{
MailMessage message;
message.setSender(sender);
message.addRecipient(MailRecipient(MailRecipient::PRIMARY_RECIPIENT, recipient));
message.setSubject("Hello from the POCO C++ Libraries");
std::string content;
content += "Hello ";
content += recipient;
content += ",\r\n\r\n";
content += "This is a greeting from the POCO C++ Libraries.\r\n\r\n";
//std::string logo(reinterpret_cast<const char*>(PocoLogo), sizeof(PocoLogo));
message.addContent(new StringPartSource(content));
//message.addAttachment("logo", new StringPartSource(logo, "image/gif"));
// new code
SocketAddress addr(mailhost, port);
StreamSocket strmSocket(addr);
DialogSocket dlgSocket(addr);
dlgSocket.sendMessage("EHLO");
std::string msg;
if(!dlgSocket.receiveMessage(msg))
throw ;
SecureStreamSocket SecStrSocket(addr);
SecStrSocket.attach(strmSocket);
msg.clear();
dlgSocket.sendMessage("EHLO");
if(!dlgSocket.receiveMessage(msg))
throw ;
SMTPClientSession session(mailhost);
session.login(SMTPClientSession::LoginMethod::AUTH_NONE, sender, "my secret password");
session.sendMessage(message);
session.close();
// end new code
}
catch (Exception& exc)
{
std::cerr << exc.displayText() << std::endl;
return 1;
}
return 0;
}
mail.exe smtp.gmail.com bla@gmail.com blah@hotmail.com
mail.exe gmail.com bla@gmail.com blah@hotmail.com
Both of them throws this exception:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
NULL pointer: _pInstance [in file "c:\dev\poco\util\include\poco\util\application.h", line 422]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Null pointer: _pInstance in file "c:\dev\poco\util\include\poco\util\application.h", line 422
I wonder if someone could help me. I don't know what I'm doing wrong and I don't have other experience with smtp and openssl.
I appreciate any help.





