Fix some issues 11
This commit is contained in:
@@ -47,6 +47,7 @@ class NotificationSettings(BaseServiceSettings):
|
||||
SMTP_PASSWORD: str = os.getenv("SMTP_PASSWORD", "")
|
||||
SMTP_TLS: bool = os.getenv("SMTP_TLS", "true").lower() == "true"
|
||||
SMTP_SSL: bool = os.getenv("SMTP_SSL", "false").lower() == "true"
|
||||
SMTP_REQUIRE_AUTH: bool = os.getenv("SMTP_REQUIRE_AUTH", "false").lower() == "true"
|
||||
|
||||
# Email Settings
|
||||
DEFAULT_FROM_EMAIL: str = os.getenv("DEFAULT_FROM_EMAIL", "noreply@bakeryforecast.es")
|
||||
|
||||
@@ -37,8 +37,15 @@ class EmailService:
|
||||
self.smtp_password = settings.SMTP_PASSWORD
|
||||
self.smtp_tls = settings.SMTP_TLS
|
||||
self.smtp_ssl = settings.SMTP_SSL
|
||||
self.smtp_require_auth = settings.SMTP_REQUIRE_AUTH
|
||||
self.default_from_email = settings.DEFAULT_FROM_EMAIL
|
||||
self.default_from_name = settings.DEFAULT_FROM_NAME
|
||||
|
||||
# Log SMTP configuration mode
|
||||
if not self.smtp_require_auth or (not self.smtp_user and not self.smtp_password):
|
||||
logger.info("Email service configured for trusted relay mode (no authentication)")
|
||||
else:
|
||||
logger.info("Email service configured with SMTP authentication")
|
||||
|
||||
async def send_email(
|
||||
self,
|
||||
@@ -287,9 +294,12 @@ class EmailService:
|
||||
else:
|
||||
raise starttls_error
|
||||
|
||||
# Login only if credentials are provided (optional for trusted relay)
|
||||
if self.smtp_user and self.smtp_password:
|
||||
# Login only if required by configuration or if credentials are provided
|
||||
# This allows for trusted relay mode where authentication is not needed
|
||||
if self.smtp_require_auth and self.smtp_user and self.smtp_password:
|
||||
await server.login(self.smtp_user, self.smtp_password)
|
||||
elif not self.smtp_require_auth:
|
||||
logger.debug("Skipping SMTP authentication - trusted relay mode")
|
||||
await server.quit()
|
||||
|
||||
logger.info("Email service health check passed")
|
||||
@@ -327,9 +337,12 @@ class EmailService:
|
||||
if self.smtp_tls and not self.smtp_ssl:
|
||||
await server.starttls()
|
||||
|
||||
# Login only if credentials are provided (optional for trusted relay)
|
||||
if self.smtp_user and self.smtp_password:
|
||||
# Login only if required by configuration or if credentials are provided
|
||||
# This allows for trusted relay mode where authentication is not needed
|
||||
if self.smtp_require_auth and self.smtp_user and self.smtp_password:
|
||||
await server.login(self.smtp_user, self.smtp_password)
|
||||
elif not self.smtp_require_auth:
|
||||
logger.debug("Skipping SMTP authentication - trusted relay mode")
|
||||
|
||||
# Send email
|
||||
await server.send_message(message, from_addr=from_email, to_addrs=[to_email])
|
||||
|
||||
Reference in New Issue
Block a user