Don't send non-transactional emails when opted out - #3615
Merged
Conversation
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>
OpenAPI ChangesNo changes detected Unexpected changes? Ensure your branch is up-to-date with |
Contributor
There was a problem hiding this comment.
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_emailto take aUserinstance (instead of a recipient list) and add a requiredis_transactionalflag. - Apply the new API to welcome and digest email send paths, setting
is_transactional=Truefor welcome andFalsefor digests. - Add tests for the new opt-in/opt-out behavior and a new
send_test_emailmanagement 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. |
shanbady
self-requested a review
July 15, 2026 13:55
shanbady
requested changes
Jul 15, 2026
shanbady
left a comment
Contributor
There was a problem hiding this comment.
left a note about a copilot comment which is probably worth addressing
Contributor
Author
|
@shanbady Addressed your feedback |
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>
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_emailcommand 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.