int SendEtsyEmail() 
  {
       // SSLInitializer sslInitializer;
       //std::string  smtpServer     = "smtp-relay.sendinblue.com";
       std::string  smtpServer     = "smtp.gmail.com";
       Poco::UInt16 port           = 587;
       //std::string  username       = "Zipper";//
      std::string username = "[email protected]";
      std::string password = "%^&\*(#967";
      //std::string password       = "zurebvomorvaufke";Tried using gmail App password
      std::string senderName     = "DR Seus";
      std::string senderEmail    = "[email protected]";
      std::string recipientEmail = "[email protected]";
      std::string subject        = "Test Email sent from Zipper";
      std::string content        = "Hello, this is a test email. Sending this from Zipper!";
      try {
          SharedPtr\<InvalidCertificateHandler\> pCert = new ConsoleCertificateHandler(false);
          Context::Ptr pContext = new Context(Context::CLIENT_USE, "");
          // Disable TLS 1.3
          //pContext-\>disableProtocols(Poco::Net::Context::PROTO_TLSV1_3);
           SSLManager::instance().initializeClient(0, pCert, pContext);
          //SSLManager::instance().initializeClient(0, nullptr, pContext);
          Poco::Net::MailMessage message;
          message.setSender(senderName + " \<" + senderEmail + "\>");
          message.addRecipient(Poco::Net::MailRecipient(
                            Poco::Net::MailRecipient::PRIMARY_RECIPIENT,
                            recipientEmail));
          message.setSubject(subject);
          message.setContentType("text/plain"); 
          message.setContent(content);
          Poco::Net::SecureSMTPClientSession session(smtpServer, 587);
          session.login();
          session.startTLS(pContext);
          //session.startTLS();

          if (!username.empty()) {
               session.login(Poco::Net::SecureSMTPClientSession::AUTH_LOGIN,
                             username, password);
          }
          session.sendMessage(message);
          session.close();
          std::cout << "Email sent successfully!" << std::endl;
          return 0;
   }
 
   catch (const std::exception & ex) {
      std::stringstream ss;
      ss << "Failed to send email: " << ex.what() << std::endl;
      std::string errorMessage = ss.str();
      return 1;
   }

}

Code is failing on session.startTLS "SSL Connection Unexpectantly Closed" I saw a message from GMAIL stating they were not allowing app connections after 5/31/2023 and I need to login via google. I then also tried creating an app password and logging in that way but did not work. I then tried another email server but still same issue.

0

There are 0 best solutions below