feat: switch email delivery from Resend to SMTP with libcurl integration
This commit is contained in:
@@ -5,8 +5,24 @@
|
||||
#include "repositories/MigrationRunner.h"
|
||||
|
||||
#include <cstdio>
|
||||
#include <fstream>
|
||||
#include <cstdlib>
|
||||
#include <fstream>
|
||||
#include <string_view>
|
||||
|
||||
namespace
|
||||
{
|
||||
bool parseEnvBool(const char *value)
|
||||
{
|
||||
if (value == nullptr)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
const std::string_view normalized(value);
|
||||
return normalized == "1" || normalized == "true" || normalized == "TRUE" ||
|
||||
normalized == "yes" || normalized == "on";
|
||||
}
|
||||
} // namespace
|
||||
|
||||
int main()
|
||||
{
|
||||
@@ -19,6 +35,7 @@ int main()
|
||||
{
|
||||
configFile >> config;
|
||||
|
||||
// DB config from env
|
||||
if (const char* envHost = std::getenv("DB_HOST"))
|
||||
config["db_clients"][0]["host"] = envHost;
|
||||
if (const char* envPort = std::getenv("DB_PORT"))
|
||||
@@ -32,16 +49,35 @@ int main()
|
||||
if (const char* envTimeout = std::getenv("DB_TIMEOUT"))
|
||||
config["db_clients"][0]["timeout"] = std::stod(envTimeout);
|
||||
|
||||
// Mail config from env
|
||||
if (const char* envMailProvider = std::getenv("MAIL_PROVIDER"))
|
||||
config["custom_config"]["mail"]["provider"] = envMailProvider;
|
||||
if (const char* envMailApiBaseUrl = std::getenv("RESEND_API_BASE_URL"))
|
||||
config["custom_config"]["mail"]["api_base_url"] = envMailApiBaseUrl;
|
||||
if (const char* envMailApiKey = std::getenv("RESEND_API_KEY"))
|
||||
config["custom_config"]["mail"]["api_key"] = envMailApiKey;
|
||||
if (const char* envSmtpHost = std::getenv("SMTP_HOST"))
|
||||
config["custom_config"]["mail"]["host"] = envSmtpHost;
|
||||
if (const char* envSmtpPort = std::getenv("SMTP_PORT"))
|
||||
config["custom_config"]["mail"]["port"] = std::stoi(envSmtpPort);
|
||||
if (const char* envSmtpUsername = std::getenv("SMTP_USERNAME"))
|
||||
config["custom_config"]["mail"]["username"] = envSmtpUsername;
|
||||
if (const char* envSmtpPassword = std::getenv("SMTP_PASSWORD"))
|
||||
config["custom_config"]["mail"]["password"] = envSmtpPassword;
|
||||
else if (const char* envResendApiKey = std::getenv("RESEND_API_KEY"))
|
||||
config["custom_config"]["mail"]["password"] = envResendApiKey;
|
||||
if (const char* envSmtpUseTls = std::getenv("SMTP_USE_TLS"))
|
||||
config["custom_config"]["mail"]["use_tls"] = parseEnvBool(envSmtpUseTls);
|
||||
if (const char* envSmtpUseStartTls = std::getenv("SMTP_USE_STARTTLS"))
|
||||
config["custom_config"]["mail"]["use_starttls"] = parseEnvBool(envSmtpUseStartTls);
|
||||
if (const char* envSmtpVerifyPeer = std::getenv("SMTP_VERIFY_PEER"))
|
||||
config["custom_config"]["mail"]["verify_peer"] = parseEnvBool(envSmtpVerifyPeer);
|
||||
if (const char* envSmtpVerifyHost = std::getenv("SMTP_VERIFY_HOST"))
|
||||
config["custom_config"]["mail"]["verify_host"] = parseEnvBool(envSmtpVerifyHost);
|
||||
if (const char* envMailFrom = std::getenv("MAIL_FROM"))
|
||||
config["custom_config"]["mail"]["from"] = envMailFrom;
|
||||
|
||||
// CORS config from env
|
||||
if (const char* envCorsAllowedOrigin = std::getenv("CORS_ALLOWED_ORIGIN"))
|
||||
config["custom_config"]["cors"]["allowed_origin"] = envCorsAllowedOrigin;
|
||||
|
||||
// CIE auth config from env
|
||||
if (const char* envCieServiceBaseUrl = std::getenv("CIE_AUTH_SERVICE_BASE_URL"))
|
||||
config["custom_config"]["cie_auth"]["service_base_url"] = envCieServiceBaseUrl;
|
||||
if (const char* envCieStartPath = std::getenv("CIE_AUTH_START_PATH"))
|
||||
@@ -52,6 +88,7 @@ int main()
|
||||
config["custom_config"]["cie_auth"]["state_ttl_minutes"] = std::stoi(envCieStateTtl);
|
||||
if (const char* envCieFrontendRedirect = std::getenv("CIE_AUTH_DEFAULT_FRONTEND_REDIRECT_URI"))
|
||||
config["custom_config"]["cie_auth"]["default_frontend_redirect_uri"] = envCieFrontendRedirect;
|
||||
|
||||
drogon::app().loadConfigJson(config);
|
||||
}
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user