Skip to content

Conversation

@Gagan-Ram
Copy link
Member

@Gagan-Ram Gagan-Ram commented Jun 21, 2025

fixes: #658

Summary by Sourcery

Implement an email outbox system in the sendmail plugin by queuing emails in the database instead of sending them immediately.

New Features:

  • Introduce a QueuedMail model to persist outgoing emails with metadata and attachments.
  • Queue emails in the SenderView rather than dispatching them immediately via a background task.
  • Add outbox management views and templates to list, send (all or individual), delete, and purge queued emails.
  • Register new URLs and navigation entries for the outbox interface.

Enhancements:

  • Switch to get_email_context for placeholder resolution when queuing emails.
  • Support customizable ordering in the outbox list view.

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Jun 21, 2025

Reviewer's Guide

This PR replaces immediate asynchronous email dispatch with a persistent outbox queue: it introduces a QueuedMail model, enqueues messages per order and attendee using the new model, and adds outbox management views, URLs, templates, and navigation to review, send, or purge queued mails.

Sequence diagram for email queuing in the new outbox flow

sequenceDiagram
    actor Admin
    participant SenderView
    participant QueuedMail
    participant DB as Database

    Admin->>SenderView: Submit email form
    SenderView->>QueuedMail: Create QueuedMail for each recipient
    QueuedMail->>DB: Save QueuedMail instance(s)
    SenderView-->>Admin: Show success message
Loading

Sequence diagram for sending all queued emails from the outbox

sequenceDiagram
    actor Admin
    participant OutboxListView
    participant QueuedMail
    participant DB as Database

    Admin->>OutboxListView: Click 'Send all' button
    OutboxListView->>QueuedMail: Fetch unsent mails
    loop For each unsent mail
        OutboxListView->>QueuedMail: send()
        QueuedMail->>DB: Update sent, sent_at
    end
    OutboxListView-->>Admin: Show result message
Loading

ER diagram for QueuedMail and related entities

erDiagram
    QUEUEDMAIL ||--o{ EVENT : event
    QUEUEDMAIL }o--|| USER : user
    QUEUEDMAIL ||--o{ ORDER : order
    QUEUEDMAIL }o--|| ORDERPOSITION : position

    QUEUEDMAIL {
        bigint id PK
        varchar recipient
        text subject
        text message
        varchar reply_to
        text bcc
        varchar locale
        json attachments
        datetime created
        boolean sent
        datetime sent_at
    }
Loading

Class diagram for the new QueuedMail model

classDiagram
    class QueuedMail {
        +Event event
        +User user
        +Order order
        +OrderPosition position
        +str recipient
        +str subject
        +str message
        +str reply_to
        +str bcc
        +str locale
        +JSON attachments
        +datetime created
        +bool sent
        +datetime sent_at
        +make_text(signature)
        +send(event_signature)
    }
    QueuedMail --> Event
    QueuedMail --> User
    QueuedMail --> Order
    QueuedMail --> OrderPosition
Loading

File-Level Changes

Change Details Files
Refactor email sending to queue instead of immediate dispatch
  • Removed send_mails.apply_async call
  • Looped over orders and attendees to create QueuedMail instances
  • Switched to get_email_context for placeholder rendering
  • Commented-out original log_action call
src/pretix/plugins/sendmail/views.py
Introduce QueuedMail model and migration
  • Added QueuedMail fields (recipient, subject, message, metadata)
  • Implemented make_text and send() methods with exception handling
  • Created initial Django migration for QueuedMail table
src/pretix/plugins/sendmail/models.py
src/pretix/plugins/sendmail/migrations/0001_initial.py
Add outbox management views
  • OutboxListView with pagination and ordering
  • SendAllQueuedMailsView to dispatch all unsent mails
  • SendQueuedMailView for single-mail send
  • DeleteQueuedMailView and PurgeQueuedMailsView for discarding mails
src/pretix/plugins/sendmail/views.py
Register outbox routes
  • Added URL patterns for outbox list, send all, send single, delete, and purge actions
src/pretix/plugins/sendmail/urls.py
Provide outbox UI template
  • Created outbox_list.html showing queued mails with action buttons
  • Included pagination and batch send/purge forms
src/pretix/plugins/sendmail/templates/pretixplugins/sendmail/outbox_list.html
Add navigation entry for Outbox
  • Inserted 'Outbox' child link in control_nav_import signal
  • Set active state based on URL namespace and name
src/pretix/plugins/sendmail/signals.py

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@mariobehling
Copy link
Member

mariobehling commented Jun 27, 2025

Thanks for this draft. Please ensure the following works as well:

  • Align buttons next to each other or in the same way as existing styles
  • Fix button texts, e.g. "Send to Outbox" instead of "Send"
  • Fix -all- relevant helper texts, e.g. "Your email has been sent to the outbox." instead of "Your email will be sent...", "Your email has been sent." etc.
  • Add option: Do you really want to delete this mail?
  • Please test and document that the feature works with a larger number of attendees/recipients.
  • Include the helper text below the text fields same as on the original email compose form.
  • Attachment option is missing in email edit form.

Screenshot from 2025-06-27 08-37-47

@Gagan-Ram
Copy link
Member Author

@mariobehling Could you please clarify/elaborate more on the below:

  • Align buttons next to each other or in the same way as existing styles
  • Include the helper text below the text fields same as on the original email compose form.

@mariobehling
Copy link
Member

Below are two examples. Please check all button implementations and ensure they follow existing styles and placements on the platform.

Screenshot from 2025-06-28 11-02-37
Screenshot from 2025-06-28 11-02-14

@hpdang
Copy link
Member

hpdang commented Jul 3, 2025

@Gagan-Ram how about the handling multiple receivers? Is it going to be done today too?

@hpdang
Copy link
Member

hpdang commented Jul 5, 2025

@Gagan-Ram I saw you opened a new PR for multiple receivers. Why is it still in draft mode?

@Gagan-Ram
Copy link
Member Author

@hpdang Sorry I didn't notice your message, maybe it was cleared from my notification when I was clearing stale ones.
The PR was in draft mode because of the mail system bug I was talking about last week. However the PR is now working as you have requested.

@Gagan-Ram
Copy link
Member Author

I am closing this PR as the newer PR #780 is more aligned with the changes requested by maintainers.
Thank you

@Gagan-Ram Gagan-Ram closed this Jul 10, 2025
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.

Implement an Outbox for Emails

3 participants