27 from smtplib
import SMTPRecipientsRefused
29 from django.conf
import settings
30 from django.core.mail.message
import EmailMessage
31 from django.template
import loader, Context
32 from django.utils.translation
import ugettext_lazy
as _
34 from clm.models.user
import User
35 from clm.utils
import log
36 from clm.utils.exception
import CLMException
55 def wrap(request, *args, **kwds):
57 return f(request, *args, **kwds)
58 except SMTPRecipientsRefused, e:
59 error =
"%s %s" % (f.__name__, str(e))
74 def send(to_address, msg_text, subject):
75 from_address = settings.FROM_EMAIL
76 log.debug(0,
'%s%s%s%s%s%s%s' % (
"send_email(from='", from_address,
"', to='", to_address,
"', subject='", subject,
"')"))
78 msg = EmailMessage(subject, msg_text, from_address, [to_address])
91 ctx_dict = {
'activation_key': activation_key,
92 'site': wi_data[
'site_domain'],
93 'site_name': wi_data[
'site_name']}
96 subject =
''.join(subject.splitlines())
99 send(user.email, message, subject)
112 ctx_dict = {
'site': wi_data[
'site_domain'],
113 'site_name': wi_data[
'site_name']}
115 subject =
''.join(subject.splitlines())
118 send(user.email, message, subject)
130 ctx_dict = {
'site_name': wi_data[
'site_name']}
132 subject =
''.join(subject.splitlines())
135 for admin
in User.objects.filter(is_superuser=
True):
136 send(admin.email, message, subject)
150 ctx_dict = {
'site_name': wi_data[
'site_name'],
151 'domain': wi_data[
'site_domain'],
152 'username': user.login,
156 send(user.email, message, _(
"Password reset on %s") % wi_data[
'site_name'])
171 _(
"User account blocked on %s") % wi_data[
'site_name'])
175 _(
"User account unblocked on %s") % wi_data[
'site_name'])
190 template = loader.get_template(template_filename)
192 log.error(0,
"Cannot load template. Error: %s" % str(e))
193 raise CLMException(
'clm_template_create')
195 return template.render(Context(ctx_dict))