Skip to content

Add customisable From display name template for outgoing emails#249

Open
josephsellers wants to merge 2 commits intoabhinavxd:mainfrom
josephsellers:from-name-template
Open

Add customisable From display name template for outgoing emails#249
josephsellers wants to merge 2 commits intoabhinavxd:mainfrom
josephsellers:from-name-template

Conversation

@josephsellers
Copy link
Copy Markdown
Contributor

Closes #248

Summary

  • Adds a from_name_template field to inboxes that allows admins to customise the From display name on outgoing emails using Go template syntax
  • When set and the sender is an agent, the template is rendered with agent/inbox variables and used as the From display name, keeping the inbox's email address unchanged
  • When left blank, behaviour is unchanged (existing From field used as-is)
  • All template errors fall through silently to the inbox From — a misconfigured template never blocks email delivery

Template variables

Variable Value
{{ .Agent.FirstName }} Sending agent's first name
{{ .Agent.LastName }} Sending agent's last name
{{ .Agent.FullName }} First + last name
{{ .Inbox.Name }} Display name from the inbox's From address

Changes

  • Schema: from_name_template TEXT NOT NULL DEFAULT '' column on inboxes
  • Migration: v1.0.2 adds the column to existing databases
  • Backend: Template rendering in sendOutgoingMessage(), plumbed through inbox models/queries/interface/email channel
  • Frontend: Text input in inbox settings form with description and placeholder
  • i18n: English translation keys

Test plan

  • Default behaviour unchanged when template is blank
  • Agent name renders correctly in From header when template is set
  • Non-agent senders (system, contacts) use inbox From as-is
  • Invalid template syntax falls back to inbox From
  • Frontend field renders with placeholder and description
  • Migration runs cleanly on existing database

Happy to make adjustments based on feedback.

@abhinavxd
Copy link
Copy Markdown
Owner

Hey,

Thanks a lot for the PR!
This makes sense, I will check this over weekend.

@josephsellers
Copy link
Copy Markdown
Contributor Author

Heads up: I've rebased this branch to remove an unrelated commit (delete private notes API) that was accidentally included. The force push drops that commit — this PR now only contains the From display name template changes as intended. Sorry for the noise!

@abhinavxd
Copy link
Copy Markdown
Owner

Hey,

I missed this will check over this weekend.

Allow inbox admins to configure a Go template that controls the
display name in the From header of outgoing emails. When set, agent
and inbox name variables are rendered into the display name while
keeping the inbox email address unchanged.

Template variables: .Agent.FirstName, .Agent.LastName, .Agent.FullName,
.Inbox.Name

Example: "{{ .Agent.FirstName }} at {{ .Inbox.Name }}" renders as
"Jane at Rokesmith Support <support@rokesmith.com>"

Empty template (default) preserves current behaviour.

[Used Claude Code 🤖]
@josephsellers
Copy link
Copy Markdown
Contributor Author

I've updated the migration to use a descriptive function name (FromNameTemplate) rather than claiming a version number. The version string in upgrade.go is a placeholder with a TODO for you to assign the right version when merging. Just wanted to make sure it doesn't collide with your release numbering.

Comment thread cmd/upgrade.go Outdated
{"v0.10.0", migrations.V0_10_0},
{"v1.0.1", migrations.V1_0_1},
// TODO: version TBD -- maintainer to assign the next migration version.
{"v1.0.2", migrations.FromNameTemplate},
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can add it to the next version v1.1.0

)

// FromNameTemplate adds the from_name_template column to the inboxes table.
func FromNameTemplate(db *sqlx.DB, fs stuffbin.FileSystem, ko *koanf.Koanf) error {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This migration should go into the v1.1.0.go file. Similar to other migrations in this app.

}
}
}
}
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should skip this if the sender is a System user, as System user sends automated emails.

And log all errors, plus there could be a validation on the frontend for golangs template syntax.
As right now if someone puts incorrect value they would never know what happened.

- Move migration to v1.1.0.go following existing naming convention
- Skip System users (automated emails) in template rendering
- Log all template errors instead of silently falling through
- Add frontend validation for balanced delimiters and known variables

[Used Claude Code 🤖]
@josephsellers
Copy link
Copy Markdown
Contributor Author

Thanks for the review! I've pushed a commit addressing all three points:

Migration (v1.1.0): Renamed the file to v1.1.0.go and the function to V1_1_0, following the existing convention. Removed the TODO.

System user skip: Added an explicit IsSystemUser() check so automated emails bypass the template entirely.

Error logging: All four error paths (agent fetch, address parse, template parse, template execute) are now logged. The fallback behaviour is the same: if anything fails, the inbox's From address is used as-is and the email still sends.

Frontend validation: Added two checks on the form field: balanced {{ }} delimiters, and a known-variables check against the four documented variables. Error messages are shown inline via the existing form validation. This catches typos and syntax mistakes before saving, rather than only surfacing them in server logs at send time.

@abhinavxd
Copy link
Copy Markdown
Owner

Hi there's a merge conflict due to recent live chat PR merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: Customisable From display name on outgoing emails

2 participants