> --
> You received this message because you are subscribed to the Google Groups "Django users" group.
> To post to this group, send email to django...@googlegroups.com.
> To unsubscribe from this group, send email to django-users...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
>
- Jason
> What do You mean "current Site object"?
from django.contrib.sites.models import Site
current_site = Site.objects.get_current()
email_vars = Context({'registration_hash' : '123456',
'new_email' : 'ma...@mail.com',
'current_site': current_site})
Documented here:
http://docs.djangoproject.com/en/1.2/ref/contrib/sites/#getting-the-current-domain-for-full-urls
- Jason
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',
[m...@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 = 'frs...@mydomain.org'
SERVER_EMAIL = 'frs...@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.