Replies: 3 comments
-
|
Does it work with the latest version of Poco? |
Beta Was this translation helpful? Give feedback.
-
|
Did you mean the 1.14.0 version? I haven't tried it, but I can give it a try. Poco 1.11.0 doesn't support OAuth 2.0, let me know if you have any idea. |
Beta Was this translation helpful? Give feedback.
-
AnalysisThis is not a POCO bug - it's a code sequence error. The ProblemYour code calls secureSessionPtr->login(Poco::Net::SMTPClientSession::AUTH_XOAUTH2, sender_email, AuthToken); // ❌ Auth FIRST
secureSessionPtr->startTLS(); // TLS secondWhy This Fails
Correct OrderFrom POCO's SecureSMTPClientSession session(mailhost);
session.login(); // 1. Initial EHLO (no auth)
session.startTLS(pContext); // 2. Upgrade to TLS
session.login(SMTPClientSession::AUTH_XOAUTH2, // 3. Auth AFTER TLS
username, password);
session.sendMessage(message);Corrected CodePoco::Net::initializeSSL();
SharedPtr<InvalidCertificateHandler> pCert = new AcceptCertificateHandler(false);
Context::Ptr pContext = new Context(
Context::TLS_CLIENT_USE, "",
Context::VERIFY_RELAXED, // Use VERIFY_RELAXED for Outlook
9, true);
SSLManager::instance().initializeClient(nullptr, pCert, pContext);
SecureSMTPClientSession session(smtpHost, port);
session.login(); // Initial EHLO
session.startTLS(pContext); // Upgrade to TLS
session.login(SMTPClientSession::AUTH_XOAUTH2, // Authenticate
sender_email, AuthToken);
session.sendMessage(message);
session.close();
Poco::Net::uninitializeSSL();Additional Notes
Please try the corrected flow and let us know if it works. This is a usage question rather than a bug, so I'd recommend converting this to a Q&A discussion. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I am trying to send an email using OAUTH2.0 Authentication type, using Poco 1.11.0 version, but I am getting the below expectation.
Your email system reported an error sending mail. details: [POCO (class Poco::Net::SMTPException - 0): SMTP Exception: The mail service does not support XOAUTH2 authentication: 250-MA1PEPF00007263.mail.protection.outlook.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]
Please review the code snippet below and let me know your thoughts.
#include
#include
#include <Poco/JSON/Parser.h>
#include "Poco/Net/MailMessage.h"
#include "Poco/Net/MailRecipient.h"
#include "Poco/Net/SMTPClientSession.h"
#include "Poco/Net/StringPartSource.h"
#include "Poco/Net/NetException.h"
#include "Poco/Net/SecureSMTPClientSession.h"
#include "Poco/Net/SslManager.h"
#include "Poco/Net/HTTPRequest.h"
#include "Poco/Net/HTTPSClientSession.h"
#include "Poco/Net/HTTPResponse.h"
#include <Poco/Net/AcceptCertificateHandler.h>
#include <Poco/Net/Context.h>
int main(int argc, char** argv)
{
string AuthToken = //Getting from other function.
string smtpHost = "Servername";
Poco::UInt16 port = 25;
try {
// Initialize SSL Context for STARTTLS
// POCO SSL initialization.
std::shared_ptr sessionPtr;
}
Beta Was this translation helpful? Give feedback.
All reactions