Opened 9 years ago

Closed 9 years ago

#24419 closed New feature (fixed)

Provide an easy way to test email connection

Reported by: Gavin Wahl Owned by: Loek van Gent
Component: Core (Mail) Version: dev
Severity: Normal Keywords:
Cc: cmawebsite@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

When configuring django to send emails through an SMTP server, there are usually many different settings to try to get it to work. I've written a management command that just sends an email to make testing the settings easier. I'm wonder if there's any interest in including this command in django?

Here's the command: https://github.com/fusionbox/django-fusionbox/blob/master/fusionbox/core/management/commands/send_test_email.py

Change History (8)

comment:1 by Collin Anderson, 9 years ago

Cc: cmawebsite@… added

The django developers list is usually the best place to discuss new features.

My thoughts on your code:

  • If you set from_email=None, it should pick up the defaults automatically.
  • fail_silently defaults to False.

Maybe it would be more useful to try to mimic the unix mail/sendmail commands, so you can use it even for non testing situations.

comment:2 by Tim Graham, 9 years ago

I don't see much advantage to a management command compared to opening a shell and invoking send_mail() as you see fit (besides saving some keystrokes).

comment:3 by Tim Graham, 9 years ago

Summary: Testing email settingsProvide an easy way to test email connection
Triage Stage: UnreviewedAccepted
Type: UncategorizedNew feature

From the mailing list thread:

Russ: "However, the counterpoint to that is that you can't just reload settings, so you have to retype (or rely on command history). I agree the benefit is marginal, but I think it's a nice enough convenience, and it's not going to be a major maintenance overhead, so I think it's probably worth including."

aRkadeFR: "But if I take a step back, these commands (for my projects) are only here to test that my SMTP settings are well setup. Thus, the test sending email is quite unnecessary, I would like a check that connects to the SMTP server (if the emails settings are setup else do nothing) when the application starts. (I don't know if there's something like saying to a SMTP server: am I allowed here? without sending an actual email)"

Tom (reply to aRkadeFR): "In Simple Mail Transfer Protocol terms, it definitely is (EHLO, MAIL FROM, RCPT TO, then disconnect without sending DATA). But SMTP is not the only mail backend, and smptlib does not expose that level of connection detail - it will merely raise a different exception type if any of those commands do not return 250 status."

comment:4 by Loek van Gent, 9 years ago

Owner: changed from nobody to Loek van Gent
Status: newassigned

comment:5 by Loek van Gent, 9 years ago

Has patch: set

comment:6 by Tim Graham, 9 years ago

Did you consider the comments from the mailing list thread about testing SMTP settings only without sending a mail? If it's feasible and not too difficult, I find that a bit more useful than simply duplicating send_mail().

comment:7 by Loek van Gent, 9 years ago

Something like this throws an error when SMTP creds are wrong:

from django.core import mail
from django.core.mail.backends.smtp import EmailBackend

    def _check_mail_settings(self):
        connection = mail.get_connection()
        if isinstance(connection, EmailBackend):
            connection.open()

But I think this should be a new ticket/feature. This ticket, to me, is really about sending an actual mail. Could I propose a new ticket to create testconnections (like @imgraham suggested) that's to test other connections (cache, ...) as well?

comment:8 by Tim Graham <timograham@…>, 9 years ago

Resolution: fixed
Status: assignedclosed

In d898ba1b:

Fixed #24419 -- Added sendtestemail management command

Note: See TracTickets for help on using tickets.
Back to Top