Skip to content

feat(api-server): send content as written with subject, text_body and html_body - #42

Merged
maneesha-xyz merged 1 commit into
OpenGovMail:mainfrom
Aravinda-HWK:feat/notify-raw-content
Oct 30, 2026
Merged

maneesha-xyz merged 1 commit into
OpenGovMail:mainfrom
Aravinda-HWK:feat/notify-raw-content

Conversation

@Aravinda-HWK

Copy link
Copy Markdown
Member

Description

/notify now takes subject, text_body and html_body, and sends them exactly as written, with no template applied. This is for a caller that renders its own email.

A custom template can't carry such content. Templates are parsed with html/template, not text/template as the README said:

  • Values passed in template_data are HTML-escaped in every block, the subject and plain body included. An HTML body arrives as escaped text, and & in a subject arrives as &.
  • Content written into the template runs any {{ it contains as template code.

Type of Change

  • Bug fix
  • New feature
  • Documentation update
  • Code refactoring
  • Other (please describe):

Changes Made

  • internal/api/handlers.go: subject, text_body and html_body on the request. With any of them set, at least one body is required, and template can't be set too (400). Each recipient gets the content as written.
  • internal/emailer/emailer.go: SendMessage sends a Message (subject and bodies) as written. Template sends now render into a Message and go out the same way. Both bodies give multipart/alternative; one body gives a single part.
  • README.md: documents the fields, and corrects the template syntax to html/template, noting that template_data values are escaped.
  • First tests for the API server: request validation, and the built message (content not escaped or templated, single-part and multipart).

Testing

go vet ./... and go test ./... in api-server. Template sends are unchanged: the rendering code moved, not its logic. Not yet run against a live SMTP server.

Checklist

  • My code follows the project's coding standards
  • I have tested my changes
  • I have updated the documentation (if needed)
  • My changes don't introduce new warnings or errors

Related Issues

Needed by OpenNSW/nsw-srilanka#919, which sends TNSW's notification email through PingMailer (OpenNSW/nsw-srilanka#917).

… html_body

A caller that renders its own email had to pass it through a custom
template, and templates are parsed with html/template: values from
template_data are HTML-escaped in every block, and content written into
the template runs as template code. /notify now also takes subject,
text_body and html_body, sent as they are with no template applied. At
least one body is required, and they can't be combined with template.

The emailer renders a template into a Message and sends it the same way,
as multipart/alternative with both bodies or a single part with one.
The README documents the fields and corrects the template syntax it
named (html/template, not text/template).
mushrafmim added a commit to mushrafmim/nsw-srilanka that referenced this pull request Oct 29, 2026
…n v0.3.0

Bump core/notification to v0.3.0 and add notification.providers.smtp, its
SMTP provider, beside the PingMailer email provider. Both send email, so a
config sets one of them; setting both is refused.

PingMailer takes only a template and template data until
OpenGovMail/pingmailer#42 is deployed, so it can't send our rendered email
yet. The example configs and the Helm values send email through smtp, with
NOTIFICATION_SMTP_PASSWORD as its secret.

Refs OpenNSW#917

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Aravinda-HWK
Aravinda-HWK marked this pull request as ready for review October 29, 2026 15:57

@maneesha-xyz maneesha-xyz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM.

@maneesha-xyz
maneesha-xyz merged commit a3fe9c8 into OpenGovMail:main Oct 30, 2026
5 checks passed
mushrafmim added a commit to mushrafmim/nsw-srilanka that referenced this pull request Oct 30, 2026
…n v0.3.0

Bump core/notification to v0.3.0 and add notification.providers.smtp, its
SMTP provider, beside the PingMailer email provider. Both send email, so a
config sets one of them; setting both is refused.

PingMailer takes only a template and template data until
OpenGovMail/pingmailer#42 is deployed, so it can't send our rendered email
yet. The example configs and the Helm values send email through smtp, with
NOTIFICATION_SMTP_PASSWORD as its secret.

Refs OpenNSW#917

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
mushrafmim added a commit to mushrafmim/nsw-srilanka that referenced this pull request Oct 31, 2026
…n v0.3.0

Bump core/notification to v0.3.0 and add notification.providers.smtp, its
SMTP provider, beside the PingMailer email provider. Both send email, so a
config sets one of them; setting both is refused.

PingMailer takes only a template and template data until
OpenGovMail/pingmailer#42 is deployed, so it can't send our rendered email
yet. The example configs and the Helm values send email through smtp, with
NOTIFICATION_SMTP_PASSWORD as its secret.

Refs OpenNSW#917

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
sthanikan2000 pushed a commit to mushrafmim/nsw-srilanka that referenced this pull request Nov 1, 2026
…n v0.3.0

Bump core/notification to v0.3.0 and add notification.providers.smtp, its
SMTP provider, beside the PingMailer email provider. Both send email, so a
config sets one of them; setting both is refused.

PingMailer takes only a template and template data until
OpenGovMail/pingmailer#42 is deployed, so it can't send our rendered email
yet. The example configs and the Helm values send email through smtp, with
NOTIFICATION_SMTP_PASSWORD as its secret.

Refs OpenNSW#917

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Aravinda-HWK pushed a commit to mushrafmim/nsw-srilanka that referenced this pull request Nov 2, 2026
…n v0.3.0

Bump core/notification to v0.3.0 and add notification.providers.smtp, its
SMTP provider, beside the PingMailer email provider. Both send email, so a
config sets one of them; setting both is refused.

PingMailer takes only a template and template data until
OpenGovMail/pingmailer#42 is deployed, so it can't send our rendered email
yet. The example configs and the Helm values send email through smtp, with
NOTIFICATION_SMTP_PASSWORD as its secret.

Refs OpenNSW#917

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
zaeema-n pushed a commit to zaeema-n/nsw-srilanka that referenced this pull request Nov 3, 2026
…notification v0.3.0 (OpenNSW#962)

* feat(notification)!: send email through PingMailer with core/notification v0.2.0

Replace github.com/OpenNSW/core/notifications with
github.com/OpenNSW/core/notification v0.2.0. Its email provider posts to
PingMailer's POST /notify with a token from an oauth2 client, so the email
block takes auth, smtpHost, smtpPort and sender in place of token.

BREAKING CHANGE: notification.providers.email.token is gone; set auth,
smtpHost, smtpPort and sender instead. NOTIFICATION_EMAIL_TOKEN is renamed
NOTIFICATION_EMAIL_CLIENT_SECRET (Helm secret key
notification-email-client-secret).

Closes OpenNSW#917

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat(notification): make notification providers optional

Each provider under notification.providers is now optional. With none set
the server starts, and the notification extension logs each notification
as skipped. The dev and agency configs leave the section commented out, so
running the stack locally needs no gateway credentials.

Refs OpenNSW#917

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat(notification): send email straight to SMTP with core/notification v0.3.0

Bump core/notification to v0.3.0 and add notification.providers.smtp, its
SMTP provider, beside the PingMailer email provider. Both send email, so a
config sets one of them; setting both is refused.

PingMailer takes only a template and template data until
OpenGovMail/pingmailer#42 is deployed, so it can't send our rendered email
yet. The example configs and the Helm values send email through smtp, with
NOTIFICATION_SMTP_PASSWORD as its secret.

Refs OpenNSW#917

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* chore(compose): pass NOTIFICATION_SMTP_PASSWORD to the server

The SMTP provider reads {{env:NOTIFICATION_SMTP_PASSWORD}}; pass it through
so enabling SMTP needs only the config and .env, not a compose edit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat(notification): show PingMailer's email provider beside SMTP in the configs

Where the cluster can't reach the SMTP server's submission port, as in
LGC, email goes through PingMailer's API with a client credentials token.
The example and agency configs now list the email, smtp and sms providers,
commented out; the Helm example sends through email and keeps smtp
commented, and passes NOTIFICATION_EMAIL_CLIENT_SECRET from nsw-secrets.
Compose passes it through too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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.

2 participants