I'm trying to get django to email exceptions to me, now that my app is
in production.  I'm testing under Windows7 but will deploy under Linux
CENTOS

The following code works as a test (server names changed to protect the
innocent:
from django.core.mail import EmailMessage
import os
def run():
    filenames = os.listdir('.')
    filenames = [x for x in filenames if x.endswith('.py')]

    subject = "django email test"
    message = "this is a test"
    email = EmailMessage(subject, message, 'mds30 server',
[...@mydomain.org'], )
    for filename in filenames:
        email.attach_file(filename)
    email.send()
========================================================================
===================
However I cannot get django to email exceptions to me. But it is
detecting them.  Code snippets follow

-----------settings.py
DEBUG = False
TEMPLATE_DEBUG = True  #also tried False

ADMINS = (
     ('Fred Sells', m...@mydomain.org'),
)
EMAIL_HOST = "mail.mydomain.org"
EMAIL_HOST_USER = ''  #also tried with my username and password
EMAIL_HOST_PASSWORD = ''
DEFAULT_FROM_EMAIL = 'frse...@mydomain.org'
SERVER_EMAIL = 'frse...@mydomain.org'
MANAGERS = ADMINS

--------------I've put some print statements in core/handlers.base.py
and it seems ok
        print 'aaaaa', subject 
        try:
            request_repr = repr(request)
        except:
            request_repr = "Request repr() unavailable"
        message = "%s\n\n%s" % (self._get_traceback(exc_info),
request_repr)
        print 'bbbbbbbbbb', message
        print 'ccccccc', resolver.urlconf_module
        mail_admins(subject, message, fail_silently=False)
        # If Http500 handler is not installed, re-raise last exception
        if resolver.urlconf_module is None:
            raise exc_info[1], None, exc_info[2]
        # Return an HttpResponse that displays a friendly error message.
        callback, param_dict = resolver.resolve500()
        print 'dddddd',  callback, param_dict

which shows...

what you would expect, ending with
ccccccc <module 'mds30.urls' from
'C:\temp\DjangoSouthRecovery\mds30\urls.pyc'>
core.mail None
dddddd <function server_error at 0x031BEA70> {}

--------------------but when I look at core/mail/__init__.py I see
this....
def mail_admins(subject, message, fail_silently=False, connection=None):
    """Sends a message to the admins, as defined by the ADMINS
setting."""
    if not settings.ADMINS: 
        return
    print 'core.mail', connection
    EmailMessage(settings.EMAIL_SUBJECT_PREFIX + subject, message,
                 settings.SERVER_EMAIL, [a[1] for a in settings.ADMINS],
 
connection=connection).send(fail_silently=fail_silently)

----------which prints
core.mail None

looking at the code, I see that base does not pass a connection, but
mail expects one and defaults to None.  Obviously others are using this
ok, so I must be missing something.  Can someone explain what I'm
missing.



-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to