Skip to content

Add custom email templates for specific registrars#3765

Merged
rebeccacremona merged 16 commits into
developfrom
custom-email-text
Jun 4, 2026
Merged

Add custom email templates for specific registrars#3765
rebeccacremona merged 16 commits into
developfrom
custom-email-text

Conversation

@durkinm2
Copy link
Copy Markdown
Contributor

@durkinm2 durkinm2 commented Apr 8, 2026

This PR adds support for registrar-specific customization of new user activation emails, to avoid generic suspicious looking emails. It allows registrars to customize email templates, subject prefixes, closing text, and sign-offs via Django settings. I added a new dynamic email template new_user_custom_registrar.txt, and registrars can be configured in settings.py like so:

  CUSTOM_REGISTRAR_EMAILS = {
      1: {  # registrar ID
          'new_user_added_to_org_by_other': {
              "template_file": "email/new_user_custom_registrar.txt",
              "subject_prefix": "AAA-BBB: ",
              "custom_closing": "If you have questions, call X.",
              "custom_sign_off": "The Perma.cc Team"
          },
          # Additional email types can be added as needed
      },
  }

Changes:

  • perma_web/perma/email.py: Added subject_prefix handling to send_user_email()
  • perma_web/perma/settings/deployments/settings_common.py: Added CUSTOM_REGISTRAR_EMAILS setting (empty default)
  • perma_web/perma/views/user_sign_up.py: Added logic to detect and apply custom email configs based on registrar
  • perma_web/perma/templates/email/new_user_custom_registrar.txt: New dynamic email template

Testing:

  • new_user_added_to_org_by_other - tested locally
  • user_added_to_organization - needs confirmation
  • user_added_to_organization_from_bulk_form - needs confirmation

Logged in as org user test_org_user@example.com and adding a user, can see the new template being used:


Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Subject: AAA-BBB: A Perma.cc account has been created for you
From: webmaster@localhost
To: abc@example.com
Date: Tue, 07 Apr 2026 18:28:58 -0000
Message-ID: <177558653894.55.14512217329762355200@9fa2aff9ab80>

A Perma.cc account has been created for you by Test Journal.

In order to complete your account activation, please confirm your email address and set a password. It's as simple as clicking the link below. The link will be valid for the next 72 hours.

    https://perma.test:8000/password/reset/MzM/d6ogoa-8fe9c497e5fccaeb49d193c7a43bf53


If you have any questions, please call the Help Desk at x0000.


The Perma.cc Team

@durkinm2 durkinm2 requested a review from teovin April 8, 2026 20:36
Comment thread perma_web/perma/settings/deployments/settings_common.py Outdated
Comment thread perma_web/perma/templates/email/new_user_custom_registrar.txt Outdated
Comment thread perma_web/perma/templates/email/new_user_custom_registrar.txt Outdated
Comment thread perma_web/perma/templates/email/new_user_custom_registrar.txt Outdated
Comment thread perma_web/perma/views/user_sign_up.py Outdated
@teovin
Copy link
Copy Markdown
Contributor

teovin commented Apr 10, 2026

I also see in the PR description that bulk addition, and user_added_to_organization flows weren't tested. Does it mean you are working on it, or that we aren't customizing the templates of those flows yet?

@teovin
Copy link
Copy Markdown
Contributor

teovin commented Apr 10, 2026

Also, let's add the config to settings_dev.py as well to make it handy for the dev team.

@durkinm2 durkinm2 marked this pull request as draft May 14, 2026 19:36
@rebeccacremona
Copy link
Copy Markdown
Contributor

Okay! To help get this to the finish line, I took the liberty of jumping in and extensively refactoring Perma's code for sending activation emails to new users.

The plot is:

  • I consolidated a bunch of templates. Now, we send new_user.txt when it's a regular user signing up themselves, and new_user_added_by_other.txt whenever an org user/registrar user/admin user creates a new user using the /manage/ pages... for instance, adding new people to an org, or adding a new sponsored user.

  • The text of the emails haven't changed in any meaningful way; a few are slightly more informative. When you get added by a person, they now all say, "A Perma.cc account has been created for you by name on behalf of entity." (E.g. "A Perma.cc account has been created for you by Rebecca Cremona on behalf of The Harvard Law Journal").

  • In the process, I thoroughly refactored how emails are sent when people upload a CSV to create lots of org users at once. It behaves exactly the same way as before, but I removed some code duplication and extracted some of its logic out of the base class into subclass-specific helpers.

  • I tweaked Mike's implementation of the custom email to accept fully customizable subject lines, and moved the logic out of the view into new helpers in email.py, but kept all of his implementation in design and spirit.

  • In response to Ebru's review above: I tweaked things so that, instead of passing the org (or registrar) name into the custom email as a variable... we can just paste the exact text the registrar wants into the config variable, without needing to fuss with variables at all.

  • I asked my agent for type annotations to be added in a few places, because I thought the situation was intricate enough that all these new helper functions could benefit from them.

Testing:

I only tested while logged in as an admin user. But, I tested:

  • signing up normally
  • signing up as part of a new registrar request
  • adding a new regular user, a new org user, a new sponsored user, a new registrar user, and a new admin user, from the /manage/ interface
  • adding a mixture of new users and existing regular users to an organization using the CSV upload feature

And, I did all the above both with and without a custom registrar email configured. And, it LGTM.

There are also some new unit tests, designed to give these paths a little exercise, if not exhaustively test everything.

Review:

Before we merge, I suggest:

  • somebody else pull it down and give it a try

  • somebody else do a quick read of the diff and see if anything is particularly unclear... OR particularly "Obviously Claude wrote this and not Becky". I made extensive use of Claude Opus to implement my intended changes; I read every line, went through several iterations, and hand-edited the final product, but at this point I am too familiar with the diff to be objective about what looks idiomatic.

I am not sure who to request help out with that. @durkinm2 @teovin what do you think?

@rebeccacremona
Copy link
Copy Markdown
Contributor

image

Okay, I'm going to go ahead and merge this. We can coordinate adding the correct production setting and deploying it in a bit.

@rebeccacremona rebeccacremona marked this pull request as ready for review June 4, 2026 18:35
@rebeccacremona rebeccacremona merged commit 7f7a428 into develop Jun 4, 2026
2 checks passed
@rebeccacremona rebeccacremona deleted the custom-email-text branch June 4, 2026 18:35
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.

3 participants