Skip to content

Don't send non-transactional emails when opted out - #3615

Merged
rhysyngsun merged 4 commits into
mainfrom
nl/email-optin-gating
Jul 16, 2026
Merged

Don't send non-transactional emails when opted out#3615
rhysyngsun merged 4 commits into
mainfrom
nl/email-optin-gating

Conversation

@rhysyngsun

Copy link
Copy Markdown
Contributor

What are the relevant tickets?

Part of https://github.com/mitodl/hq/issues/8424

Description (What does it do?)

Send emails to a User instance rather than a raw recipient list, and add an is_transactional flag so non-transactional email (e.g. digests) can respect the user's email_optin preference while transactional email (e.g. welcome) still always sends.

How can this be tested?

You can use the send_test_email command to help test emails. The welcome email should send for your user but not the digest one if you're opted out and both should send if you're opted in.

rhysyngsun and others added 2 commits July 14, 2026 16:59
Send emails to a User instance rather than a raw recipient list, and add
an is_transactional flag so non-transactional email (e.g. digests) can
respect the user's email_optin preference while transactional email
(e.g. welcome) still always sends.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 14, 2026 21:32
@github-actions

github-actions Bot commented Jul 14, 2026

Copy link
Copy Markdown

OpenAPI Changes

No changes detected

View full changelog

Unexpected changes? Ensure your branch is up-to-date with main (consider rebasing).

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the email-sending utilities and callers so that non-transactional emails (e.g., digests) respect a user’s email_optin preference, while transactional emails (e.g., welcome emails) still always send. It also adds a management command to help manually test the welcome vs digest behavior.

Changes:

  • Change send_template_email / send_email to take a User instance (instead of a recipient list) and add a required is_transactional flag.
  • Apply the new API to welcome and digest email send paths, setting is_transactional=True for welcome and False for digests.
  • Add tests for the new opt-in/opt-out behavior and a new send_test_email management command for manual verification.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
profiles/utils.py Switch email helpers to accept a User and add transactional vs non-transactional opt-out behavior.
profiles/utils_test.py Add unit tests validating opt-in/opt-out behavior for transactional vs non-transactional emails.
profiles/tasks.py Update welcome-email task to use the new send_template_email(user, ..., is_transactional=True) API.
profiles/tasks_test.py Update expectations for the new send_template_email call signature and transactional flag.
profiles/management/commands/send_test_email.py Add a CLI utility to trigger test welcome/digest emails for a user.
learning_resources_search/tasks.py Update digest sending to pass a User and mark digest emails as non-transactional.

Comment thread profiles/utils.py Outdated
Comment thread profiles/management/commands/send_test_email.py
Comment thread profiles/management/commands/send_test_email.py
Comment thread profiles/management/commands/send_test_email.py
@shanbady
shanbady self-requested a review July 15, 2026 13:55

@shanbady shanbady left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

left a note about a copilot comment which is probably worth addressing

Comment thread profiles/utils.py Outdated
@rhysyngsun

Copy link
Copy Markdown
Contributor Author

@shanbady Addressed your feedback

@shanbady shanbady left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍

@rhysyngsun
rhysyngsun merged commit 08d173f into main Jul 16, 2026
13 checks passed
@rhysyngsun
rhysyngsun deleted the nl/email-optin-gating branch July 16, 2026 17:03
alexfigtree pushed a commit that referenced this pull request Jul 16, 2026
* Don't send non-transactional emails when opted out

Send emails to a User instance rather than a raw recipient list, and add
an is_transactional flag so non-transactional email (e.g. digests) can
respect the user's email_optin preference while transactional email
(e.g. welcome) still always sends.

* Add send_test_email management command

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

* Handle missing profile case

* Exit code 1 if no user email

---------

Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
@odlbot odlbot mentioned this pull request Jul 20, 2026
12 tasks
mbertrand pushed a commit that referenced this pull request Jul 22, 2026
* Don't send non-transactional emails when opted out

Send emails to a User instance rather than a raw recipient list, and add
an is_transactional flag so non-transactional email (e.g. digests) can
respect the user's email_optin preference while transactional email
(e.g. welcome) still always sends.

* Add send_test_email management command

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

* Handle missing profile case

* Exit code 1 if no user email

---------

Co-authored-by: Claude Sonnet 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.

3 participants