Skip to content

Conversation

oneiros
Copy link
Contributor

@oneiros oneiros commented Jun 27, 2025

Fixes MAS-462

We have two types of emails (server announcements and terms of service changes) that can be sent to many users at once. Turns out some transactional email service providers do not like this and require you to use different SMTP settings for these kinds of emails.

This change moves those mails into their own mailer, which will use different SMTP settings if available.

Those new settings work exactly as the existing ones, but are prefixed with BULK_.

To make room for an actual `BulkMailer`. It is a rails convention that
all mailer class names end on `Mailer`.
@renchap
Copy link
Member

renchap commented Jun 27, 2025

This will need a documentation PR to add those configuration variables and an explanation on when they are used

Copy link
Contributor

@ClearlyClaire ClearlyClaire left a comment

Choose a reason for hiding this comment

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

Looks good overall, just a tiny typo in a test description!

@ClearlyClaire ClearlyClaire added the build-image Build a container image for this PR label Jun 27, 2025
ClearlyClaire
ClearlyClaire previously approved these changes Jun 27, 2025
@mjankowski
Copy link
Contributor

Really lovely yaml here.

@ClearlyClaire
Copy link
Contributor

We did, having everything in a specific class seemed cleaner to us.

  • I recall on some previous issue that there's a crowdin problem with moving/renaming strings this way, though I don't recall the issue details. Am I making that up?

Yes, existing translations are unfortunately invalidated. Crowdin should suggest them for the renamed strings, though.

@oneiros
Copy link
Contributor Author

oneiros commented Jun 27, 2025

* Did you contemplate using this “dynamic delivery” option vs the new bulk-focused class? https://guides.rubyonrails.org/action_mailer_basics.html#sending-emails-with-dynamic-delivery-options - presumably you’d have smaller diff that way, though I see the advantage of the isolated class as well.

Well, the new BulkMailer does use the dynamic delivery stuff, but we decided it would be tidier to have a separate class anyway. Especially since UserMailer is already quite large.

* I recall on some previous issue that there's a crowdin problem with moving/renaming strings this way, though I don't recall the issue details. Am I making that up?

Yes, there is a problem. Crowdin only picks up the english locale and will notice new keys that will all have to be translated again in all other locales. We do not know of a way to tell Crowdin that those keys only moved in an automated way. Seems like this will require some manual work in Crowdin. Happy to hear if you know of a better way.

@mjankowski
Copy link
Contributor

Sounds good. I don't have a strong opinion on which way is better. Glad it was considered.

Using delivery_method_options as an additional arg to the two mailers within the existing user mailer, along with a method/module/something to negotiate the "use bulk if present and standard if not" logic would probably minimize the diff and not require translation changes ... but breaking out the new class may be more clean and more future proof re: adding more bulk mailers, if any (though I see there is added coverage here for the bulk/optional behavior, which makes that less important).

Separately - on top of the crowdin changes, are there any implications to running/queued mailers that are in place before the rename? I know in previous PRs we'd resisted changing the method signature/naming of some of them out of concern for breaking retries.

Especially since UserMailer is already quite large.

If we could solve the "renames and signature changes might break queues" issue, I think a good refactor at some point would be to separate all of the "inherited from devise" vs "our own creations" emails within this mailer into two mailers. Would reduce the LOC of the large user mailer, and I suspect would also be a nice code cleanup on the helpers/params/subjects/i18n front, because those tend to behave consistently between the devise and non-devise methods.

@ClearlyClaire
Copy link
Contributor

Separately - on top of the crowdin changes, are there any implications to running/queued mailers that are in place before the rename? I know in previous PRs we'd resisted changing the method signature/naming of some of them out of concern for breaking retries.

Excellent point. It's a rather minor concern because those are uncommonly-used features and not part of any release yet (although they are part of betas!), but this is all true.

Copy link
Member

@Gargron Gargron left a comment

Choose a reason for hiding this comment

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

In theory, could we not keep the templates and strings where they are now, and just reference them explicitly from the new mailer?

Adds a second set of environment variables prefixed `BULK_SMTP..`
that can be used to set a different smtp configuration for
bulk emails (i.e. non-transactional emails that might be sent
to many users).
@oneiros oneiros force-pushed the feat/optional-bulk-mailer-settings branch from 2bba114 to 999f1a2 Compare June 30, 2025 13:39
@oneiros
Copy link
Contributor Author

oneiros commented Jun 30, 2025

I rewrote this without introducing a new mailer. This removes the need to move i18n keys and solves the problem of previously enqueued jobs.

I moved the logic into its own concern, so it could be re-used in other mailers (sadly, UserMailer does not inherit from ApplicationMailer).

As Matt pointed out, this makes the diff smaller, a lot smaller. And we could still tackle the bigger refactor later, e.g. when we have a third type of "bulk mail".

@ClearlyClaire ClearlyClaire added this pull request to the merge queue Jun 30, 2025
Merged via the queue into main with commit c357a7f Jun 30, 2025
35 checks passed
@ClearlyClaire ClearlyClaire deleted the feat/optional-bulk-mailer-settings branch June 30, 2025 15:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build-image Build a container image for this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants