我尝试通过 lib poco 和 ssl 发送邮件。我使用了一个非常简单的示例代码,因为它的功能对我来说已经足够了。该代码正在运行,所以它确实希望我希望他这样做,但不幸的是,在发送邮件后 CPU 负载升至 100%。每次都发生这种情况,所以我认为我在代码中犯了一个错误。有人可以给我一个提示来帮助我吗?非常感谢。
void <myclass>::sendMessageSSL() {
string to = "<toMail>";
string from = "<from>";
string subject = "Subject";
subject = MailMessage::encodeWord(subject, "UTF-8");
string content = "Content";
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 {
SecureSMTPClientSession session(host_out, port_out);
session.open();
// Initialize the NetSSL library, as well as the underlying OpenSSL libraries
initializeSSL();
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);
try {
// TLS begins with an unsecured connection
session.login();
// Upgrades to secured connection once the information is sent
if (session.startTLS(ptrContext)) {
session.login(SMTPClientSession::AUTH_LOGIN, user, pass);
session.sendMessage(message);
}
session.close();
uninitializeSSL();
} catch (SMTPException &e) {
cerr << e.displayText() << endl;
session.close();
uninitializeSSL();
}
} catch (NetException &e) {
cerr << e.displayText() << endl;
}
}