Skip to content

Commit

Permalink
feat(mailer): expose hello_name for SMTP client config (#1057)
Browse files Browse the repository at this point in the history
* feat(mailer): expose hello_name for SMTP client config

* chore: add commented out config for mailer hello name to template
  • Loading branch information
mccormickt authored Dec 8, 2024
1 parent d3489f2 commit 1737be8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
12 changes: 7 additions & 5 deletions loco-new/base_template/config/development.yaml.t
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ server:
host: http://localhost
# Out of the box middleware configuration. to disable middleware you can changed the `enable` field to `false` of comment the middleware block
middlewares:
{%- if settings.asset %}
{%- if settings.asset.kind == "server" %}
{%- if settings.asset %}
{%- if settings.asset.kind == "server" %}
static:
enable: true
must_exist: true
Expand All @@ -32,7 +32,7 @@ server:
uri: "/static"
path: "assets/static"
fallback: "assets/static/404.html"
{%- elif settings.asset.kind == "client" %}
{%- elif settings.asset.kind == "client" %}
static:
enable: true
must_exist: true
Expand All @@ -42,9 +42,9 @@ server:
path: "frontend/dist"
fallback: "frontend/dist/index.html"
{%- endif -%}

{%- endif -%}

{%- if settings.background%}

# Worker Configuration
Expand Down Expand Up @@ -83,6 +83,8 @@ mailer:
# auth:
# user:
# password:
# Override the SMTP hello name (default is the machine's hostname)
# hello_name:
{%- endif %}

# Initializers Configuration
Expand Down
2 changes: 2 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,8 @@ pub struct SmtpMailer {
pub secure: bool,
/// Auth SMTP server
pub auth: Option<MailerAuth>,
/// Optional EHLO client ID instead of hostname
pub hello_name: Option<String>,
}

/// Authentication details for the mailer
Expand Down
9 changes: 7 additions & 2 deletions src/mailer/email_sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
//! sending emails with options like sender, recipient, subject, and content.
use lettre::{
message::MultiPart, transport::smtp::authentication::Credentials, AsyncTransport, Message,
Tokio1Executor, Transport,
message::MultiPart,
transport::smtp::{authentication::Credentials, extension::ClientId},
AsyncTransport, Message, Tokio1Executor, Transport,
};
use tracing::error;

Expand Down Expand Up @@ -60,6 +61,10 @@ impl EmailSender {
.credentials(Credentials::new(auth.user.clone(), auth.password.clone()));
}

if let Some(hello_name) = config.hello_name.as_ref() {
email_builder = email_builder.hello_name(ClientId::Domain(hello_name.clone()));
}

Ok(Self {
transport: EmailTransport::Smtp(email_builder.build()),
})
Expand Down

0 comments on commit 1737be8

Please sign in to comment.