Skip to content

Simpler setting for sandbox mode #140

@okke-formsma

Description

@okke-formsma

Today I accidentally sent emails from our dev environment as I misunderstood the SENDGRID_SANDBOX_MODE_IN_DEBUG setting. Unfortunately, it's currently not easily possible to enable the sandbox without setting DEBUG=True as well.

As a workaround, I'm now using a new email Backend on our dev environment that sets sandbox mode. Maybe consider adding this, or a setting like SENDGRID_SANDBOX_MODE which does not depend on the value of other settings.

from sendgrid_backend import SendgridBackend


class SandboxSendgridBackend(SendgridBackend):
    """
    SendGrid backend that always enables sandbox mode.

    This prevents actual email delivery in non-production environments
    like QA and dev, regardless of DEBUG setting.

    Sandbox mode causes SendGrid to validate the email but not send it,
    making it safe to test email functionality without spamming users.
    """

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        # Always enable sandbox mode, overriding parent class logic
        self.sandbox_mode = True

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions