feat(smtp): complete native Lua SMTP integration for production mail delivery

- Add native Lua SMTP client with SSL/TLS support for mail.dragons-at-work.de:465
- Implement POST /v1/mail/send endpoint with real email delivery functionality
- Add environment variable integration (SMTP_*) for secure credential management
- Add comprehensive input validation and error handling for mail requests
- Add health check endpoint with SMTP configuration status reporting
- Add multi-line SMTP response handling for robust server communication
- Add request ID tracking system for debugging and monitoring
- Update start.sh script for automatic .env loading and dependency checking
- Add complete testing suite for SMTP functionality verification

This completes the Week 2 Challenge migration from Go to pure Lua HTTP server
with full production-ready SMTP capabilities. The implementation eliminates all
Google/corporate dependencies while achieving superior performance (18ms response
time) and maintaining digital sovereignty principles.

Real mail delivery confirmed: test email successfully sent to admin@dragons-at-work.de
Ready for Hugo website integration and production deployment with security layer.

Closes #65
This commit is contained in:
michael 2025-06-19 09:52:15 +02:00
parent 662bfc7b7a
commit 6d7d8a2af8
7 changed files with 510 additions and 24 deletions

View file

@ -181,7 +181,8 @@ server:add_route("GET", "/health", function(request)
status = "healthy",
service = "furt-lua",
version = "1.0.0",
timestamp = os.time()
timestamp = os.time(),
smtp_configured = config.mail and config.mail.username ~= nil
}
return server:create_response(200, response_data)
end)
@ -223,16 +224,24 @@ server:add_route("POST", "/v1/mail/send", function(request)
})
end
-- TODO: Implement actual mail sending via SMTP
print("Mail request received: " .. data.name .. " <" .. data.email .. ">")
local response_data = {
success = true,
message = "Mail queued for sending",
request_id = os.time() .. "-" .. math.random(1000, 9999)
}
return server:create_response(200, response_data)
-- Send email via SMTP
local SMTP = require("src.smtp")
local smtp_client = SMTP:new(config.mail)
local request_id = os.time() .. "-" .. math.random(1000, 9999)
local subject = data.subject or "Contact Form Message"
local email_content = string.format("From: %s <%s>\nSubject: %s\n\n%s",
data.name, data.email, subject, data.message)
local success, result = smtp_client:send_email(
config.mail.to_address, subject, email_content, data.name)
if success then
return server:create_response(200, {success = true, message = "Mail sent", request_id = request_id})
else
return server:create_response(500, {success = false, error = result, request_id = request_id})
end
end)
-- Start server