check TLS, add more error messages

This commit is contained in:
proddy
2026-08-30 15:48:58 +02:00
parent c5e2ba024c
commit 518ac0b4b4
+8 -5
View File
@@ -187,6 +187,7 @@ bool System::command_sendmail(const char * value, const int8_t) {
const bool implicit_ssl = (security == EMAIL_SECURITY::SSL); const bool implicit_ssl = (security == EMAIL_SECURITY::SSL);
const bool start_tls = (security == EMAIL_SECURITY::STARTTLS); const bool start_tls = (security == EMAIL_SECURITY::STARTTLS);
const bool tls_enabled = (security != EMAIL_SECURITY::NONE);
if (security == EMAIL_SECURITY::NONE) { if (security == EMAIL_SECURITY::NONE) {
smtp = new SMTPClient(*basic_client); smtp = new SMTPClient(*basic_client);
@@ -212,14 +213,13 @@ bool System::command_sendmail(const char * value, const int8_t) {
delete basic_client; delete basic_client;
}; };
// ssl defaults to true; Off and STARTTLS must start as plain SMTP if (!smtp->connect(server, port, String(""), static_cast<SMTPResponseCallback>(nullptr), tls_enabled)) {
if (!smtp->connect(server, port, String(""), static_cast<SMTPResponseCallback>(nullptr), implicit_ssl)) { LOG_ERROR("send email connection error: %s", smtp->status().text.c_str());
LOG_ERROR("send email connection error");
cleanup(); cleanup();
return false; return false;
} }
if (!smtp->isConnected()) { if (!smtp->isConnected()) {
LOG_ERROR("send email connection error"); LOG_ERROR("send email connection error: %s", smtp->status().text.c_str());
cleanup(); cleanup();
return false; return false;
} }
@@ -228,7 +228,7 @@ bool System::command_sendmail(const char * value, const int8_t) {
if (!login.isEmpty()) { if (!login.isEmpty()) {
smtp->authenticate(login, pass, readymail_auth_password); smtp->authenticate(login, pass, readymail_auth_password);
if (!smtp->isAuthenticated()) { if (!smtp->isAuthenticated()) {
LOG_ERROR("send email authentication error"); LOG_ERROR("send email authentication error: %s", smtp->status().text.c_str());
cleanup(); cleanup();
return false; return false;
} }
@@ -255,6 +255,9 @@ bool System::command_sendmail(const char * value, const int8_t) {
msg.timestamp = time(nullptr); msg.timestamp = time(nullptr);
success = smtp->send(msg); success = smtp->send(msg);
if (!success) {
LOG_ERROR("send email failed: %s", smtp->status().text.c_str());
}
cleanup(); cleanup();
#endif #endif