diff --git a/src/smtp.lua b/src/smtp.lua index ab59d17..4c08b97 100644 --- a/src/smtp.lua +++ b/src/smtp.lua @@ -237,6 +237,33 @@ function SMTP:send_email(to_address, subject, message, from_name) return cleanup_and_fail("EHLO failed: " .. response) end + -- STARTTLS hinzufügen für Port 587 + if self.port == 587 and self.use_ssl then + -- STARTTLS command + local success, response = self:send_command(sock, "STARTTLS", 220) + if not success then + return cleanup_and_fail("STARTTLS failed: " .. response) + end + + -- Upgrade connection to SSL + local ssl_sock, err = self.ssl_compat:wrap_socket(sock, { + mode = "client", + protocol = "tlsv1_2" + }) + + if not ssl_sock then + return cleanup_and_fail("SSL upgrade failed: " .. err) + end + + sock = ssl_sock + + -- EHLO again over encrypted connection + local success, response = self:send_command(sock, "EHLO furt-lua", 250) + if not success then + return cleanup_and_fail("EHLO after STARTTLS failed: " .. response) + end + end + -- AUTH LOGIN local success, response = self:send_command(sock, "AUTH LOGIN", 334) if not success then