基于Poco的smtp客户端和ssl连接

时间:2011-06-25 19:07:07

标签: c++ ssl smtp smtpclient poco-libraries

我正在尝试开发电子邮件客户端。 我刚开始。 我的问题是关于与c ++ lib Poco的SSL连接

这里有一些代码:

  std::string mailhost("smtp.gmail.com");
  std::string recipient("xxxxxxxxxx@gmail.com");
  std::string sender("rushmab@gmail.com");
  std::string response;
  try
    {
      Poco::Net::SSLManager &app = Poco::Net::SSLManager::instance();
      Poco::Net::initializeSSL();
      Poco::Net::MailMessage message;
      message.setSender(sender);
      message.addRecipient(Poco::Net::MailRecipient(Poco::Net::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";
      message.addContent(new Poco::Net::StringPartSource(content));
      Poco::Net::SecureSMTPClientSession session(mailhost);
     session.login();
     session.startTLS();
      session.login(Poco::Net::SMTPClientSession::AUTH_LOGIN, "xxxxxxxxxxxxxx", "xxxx");
      session.sendMessage(message);
      session.close();
    } catch (Poco::Exception& exc) {
    std::cerr << exc.displayText() << std::endl;
    return 1;
  }

这是输出

Illegal state: An application configuration is required to initialize the Poco::Net::SSLManager, but no Poco::Util::Application instance is available.

谢谢

0 个答案:

没有答案