Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot send mail using SecureSMTPClientSession if SMTP server uses Post-Handshake Session Ticket #4874

Open
exeyer opened this issue Feb 17, 2025 · 0 comments
Labels

Comments

@exeyer
Copy link

exeyer commented Feb 17, 2025

Describe the bug
Cannot send mail using SecureSMTPClientSession if SMTP server uses Post-Handshake Session Ticket. The code below works fine with GMail, it's not use session ticket.

But for many others SMTP server it's failed. For example smtp.outlook.com:

openssl s_client -connect smtp.outlook.com:587 -starttls smtp
....
250 SMTPUTF8

Post-Handshake New Session Ticket arrived:
SSL-Session:
Protocol : TLSv1.3
Cipher : TLS_AES_256_GCM_SHA384
....

To Reproduce
This code throws an exception in startTLS(): error:0A00010B:SSL routines::wrong version number
int TestEmail()
{
try
{
// Create a mail message
Poco::Net::MailMessage message;
message.setSender("[email protected]");
message.addRecipient(Poco::Net::MailRecipient(Poco::Net::MailRecipient::PRIMARY_RECIPIENT, "[email protected]"));
message.setSubject("HTML Email from Poco");

    // Set content type to HTML
    message.setContentType("text/html");

    // Provide HTML content as the message body
    message.setContent("<html><body><h1>Hello</h1><p>This is an HTML email from Poco.</p></body></html>");

    // Create an SMTP session (change the server and port accordingly)
    Poco::Net::SecureSMTPClientSession session("smtp.outlook.com", 587);
    session.setTimeout(Poco::Timespan(20, 0));
    session.open();
    std::string response;
    session.sendCommand("EHLO smtp.outlook.com\r\n", response);
    std::cout << response << std::endl;

    // Initialize the SSL manager (needed for secure connections)
    Poco::Net::initializeSSL();
    Poco::SharedPtr<Poco::Net::InvalidCertificateHandler> ptrHandler = new Poco::Net::AcceptCertificateHandler(false);
    Poco::Net::Context::Ptr ptrContext = new Poco::Net::Context(Poco::Net::Context::TLS_CLIENT_USE, "", "", "",
        Poco::Net::Context::VERIFY_NONE, 9, true, "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
  
    Poco::Net::SSLManager::instance().initializeClient(NULL, ptrHandler, ptrContext);

    session.login();
    if(session.startTLS(ptrContext))
    {
        session.login(Poco::Net::SecureSMTPClientSession::AUTH_LOGIN, "[email protected]", "******");
        session.sendMessage(message);
    }

    // Close the session
    session.close();
}
catch (Poco::Net::SMTPException& e)
{
    std::cout << e.message() << std::endl;
}
catch (Poco::Net::NetException& e)
{
    std::cout << e.message() << std::endl;
}
catch (const std::exception& e)
{
    std::cout << e.what() << std::endl;
}
// Cleanup SSL manager
Poco::Net::uninitializeSSL();

return 0;

}

Expected behavior
SecureSMTPClientSession can send messages with smtp.outlook.com, smtp.yandex.com and any others with session tickets.

Logs
250-GV3P280CA0113.outlook.office365.com Hello [xxx.xxx.xxx.xxx]
250-SIZE 157286400
250-PIPELINING
250-DSN
250-ENHANCEDSTATUSCODES
250-STARTTLS
250-8BITMIME
250-BINARYMIME
250-CHUNKING
250 SMTPUTF8
error:0A00010B:SSL routines::wrong version number

Please add relevant environment information:

  • Ubuntu 22.04.5 LTS
  • POCO 1.13.3
  • OpenSSL 3.0.2 15 Mar 2022
@exeyer exeyer added the bug label Feb 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant