Framework.Effects.Email (Framework v0.5.0)
View SourceEmail sending and template rendering for Framework effects.
Provides email sending capabilities with template rendering support. Uses Swoosh for email delivery with configurable adapters.
Configuration
Configure in your application config:
config :framework, :email_config, %{
adapter: Swoosh.Adapters.SMTP, # or Swoosh.Adapters.Test for testing
from_email: "noreply@yourapp.com",
from_name: "Your App",
templates_dir: "priv/email_templates",
# Adapter-specific config
smtp: %{
relay: "smtp.yourprovider.com",
username: "your_username",
password: "your_password",
tls: :always,
auth: :always,
port: 587
}
}Template System
Email templates are simple text files with variable interpolation:
- Subject templates:
templates_dir/<template_name>_subject.txt - Body templates:
templates_dir/<template_name>_body.txt - HTML templates (optional):
templates_dir/<template_name>_body.html
Variables in templates are replaced using {{variable_name}} syntax.
Summary
Functions
Get the configured email settings.
Render an email template with the given model variables.
Send an email using the framework's email configuration.
Functions
Get the configured email settings.
Render an email template with the given model variables.
Templates use {{variable_name}} syntax for variable interpolation.
Locale-aware Template Resolution
Templates are searched in order:
- Locale-specific:
templates_dir/{locale}/{template}_{type}.txt - Default:
templates_dir/{template}_{type}.txt
Example:
- Locale "es-ES":
priv/email_templates/es-ES/welcome_subject.txt - Fallback:
priv/email_templates/welcome_subject.txt
Send an email using the framework's email configuration.
Parameters
template: Template name (e.g., "welcome", "password_reset")to: Recipient email addressmodel: Variables for template renderingopts: Additional options:external_id- Idempotency key for logging:correlation_ids- Request correlation context
Returns
:okon successful send{:error, reason}on failure