Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unified SMTP config #257

Merged
merged 5 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@

## Release candidate

## Breaking changes
- Config option `sender_email_address` is now called `from` (#257, PLUM Sprint 230825)

### Fix
- Add id_token_signing_alg_values_supported in OIDC discovery (#260)
- Add `id_token_signing_alg_values_supported` in OIDC discovery (#260)

### Features
- Unified SMTP config (#257, PLUM Sprint 230825)

---

Expand Down
17 changes: 14 additions & 3 deletions seacatauth/communication/builders/email.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import jinja2
import re
import asab

from .abc import MessageBuilderABC

Expand All @@ -9,19 +10,29 @@ class EmailMessageBuilder(MessageBuilderABC):
Channel = "email"
ConfigDefaults = {
"template_extension": "html",
"sender_email_address": "auth@seacatauth.info",
"from": "auth@seacatauth.info",
# "template_path": "/etc/message-templates/email/", # Inherited from [seacatauth:communication]
}

def __init__(self, config_section_name, config=None):
super().__init__(config_section_name, config)
self.JinjaEnv.autoescape = jinja2.select_autoescape(['html', 'xml'])
self.Sender = self.Config.get("sender_email_address", None)

if "smtp" in asab.Config:
self.Config.update(asab.Config["smtp"])
if "sender_email_address" in self.Config:
asab.LogObsolete.warning(
"Config option 'sender_email_address' in '[smtp]' has been renamed to 'from'. "
"Please update your configuration file.",
struct_data={"eol": "2024-01-31"})
self.From = self.Config.get("sender_email_address", None)
else:
self.From = self.Config.get("from", None)

def build_message(self, template_name, locale, *, email=None, **kwargs):
message = super(EmailMessageBuilder, self).build_message(template_name, locale, **kwargs)
message["subject"] = self._get_subject_from_body(message["message_body"])
message["sender"] = self.Sender
message["sender"] = self.From
if email is None:
raise TypeError("'email' not specified")
message["to"] = email
Expand Down
2 changes: 2 additions & 0 deletions seacatauth/communication/email_smtp.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class SMTPProvider(CommunicationProviderABC):
def __init__(self, provider_id, config_section_name):
super().__init__(provider_id, config_section_name)

if "smtp" in asab.Config:
self.Config.update(asab.Config["smtp"])
self.SSL = self.Config.getboolean("ssl")
self.StartTLS = self.Config.getboolean("starttls")
self.Host = self.Config.get("host")
Expand Down
Loading