from functools import wraps
from astakos.im.settings import DEFAULT_CONTACT_EMAIL, DEFAULT_FROM_EMAIL, \
- SITENAME, BASEURL, DEFAULT_ADMIN_EMAIL, LOGGING_LEVEL
+ SITENAME, BASEURL, DEFAULT_ADMIN_EMAIL, LOGGING_LEVEL, \
+ VERIFICATION_EMAIL_SUBJECT, ADMIN_NOTIFICATION_EMAIL_SUBJECT, \
+ HELPDESK_NOTIFICATION_EMAIL_SUBJECT, INVITATION_EMAIL_SUBJECT, \
+ GREETING_EMAIL_SUBJECT, FEEDBACK_EMAIL_SUBJECT, EMAIL_CHANGE_EMAIL_SUBJECT
from astakos.im.models import Invitation, AstakosUser
logger = logging.getLogger(__name__)
'support': DEFAULT_CONTACT_EMAIL})
sender = DEFAULT_FROM_EMAIL
try:
- send_mail('%s alpha2 testing account activation is needed' % SITENAME, message, sender, [user.email])
+ send_mail(_(VERIFICATION_EMAIL_SUBJECT), message, sender, [user.email])
except (SMTPException, socket.error) as e:
logger.exception(e)
raise SendVerificationError()
'support': DEFAULT_CONTACT_EMAIL})
sender = DEFAULT_FROM_EMAIL
try:
- send_mail('%s alpha2 testing account notification' % SITENAME, message, sender, [DEFAULT_ADMIN_EMAIL])
+ send_mail(_(ADMIN_NOTIFICATION_EMAIL_SUBJECT) % {'user': user.email}, message, sender, [DEFAULT_ADMIN_EMAIL])
except (SMTPException, socket.error) as e:
logger.exception(e)
raise SendNotificationError()
msg = 'Sent admin notification for user %s' % user.email
logger._log(LOGGING_LEVEL, msg, [])
+def send_helpdesk_notification(user, template_name='im/helpdesk_notification.txt'):
+ """
+ Send email to DEFAULT_CONTACT_EMAIL to notify for a new user activation.
+
+ Raises SendNotificationError
+ """
+ if not DEFAULT_CONTACT_EMAIL:
+ return
+ message = render_to_string(template_name, {
+ 'user': user,
+ 'baseurl': BASEURL,
+ 'site_name': SITENAME,
+ 'support': DEFAULT_ADMIN_EMAIL})
+ sender = DEFAULT_FROM_EMAIL
+ try:
+ send_mail(_(HELPDESK_NOTIFICATION_EMAIL_SUBJECT) % {'user': user.email}, message, sender, [DEFAULT_CONTACT_EMAIL])
+ except (SMTPException, socket.error) as e:
+ logger.exception(e)
+ raise SendNotificationError()
+ else:
+ msg = 'Sent helpdesk admin notification for user %s' % user.email
+ logger._log(LOGGING_LEVEL, msg, [])
+
def send_invitation(invitation, template_name='im/invitation.txt'):
"""
Send invitation email.
Raises SendInvitationError
"""
- subject = _('Invitation to %s alpha2 testing' % SITENAME)
+ subject = _(INVITATION_EMAIL_SUBJECT)
url = '%s?code=%d' % (urljoin(BASEURL, reverse('astakos.im.views.index')), invitation.code)
message = render_to_string('im/invitation.txt', {
'invitation': invitation,
Raises SMTPException, socket.error
"""
- subject = _('Welcome to %s alpha2 testing' % SITENAME)
+ subject = _(GREETING_EMAIL_SUBJECT)
message = render_to_string(email_template_name, {
'user': user,
'url': urljoin(BASEURL, reverse('astakos.im.views.index')),
logger._log(LOGGING_LEVEL, msg, [])
def send_feedback(msg, data, user, email_template_name='im/feedback_mail.txt'):
- subject = _("Feedback from %s alpha2 testing" % SITENAME)
+ subject = _(FEEDBACK_EMAIL_SUBJECT)
from_email = user.email
recipient_list = [DEFAULT_CONTACT_EMAIL]
content = render_to_string(email_template_name, {
t = loader.get_template(email_template_name)
c = {'url': url, 'site_name': SITENAME}
from_email = DEFAULT_FROM_EMAIL
- send_mail(_("Email change on %s alpha2 testing") % SITENAME,
+ send_mail(_(EMAIL_CHANGE_EMAIL_SUBJECT),
t.render(Context(c)), from_email, [ec.new_email_address])
except (SMTPException, socket.error) as e:
logger.exception(e)
msg = 'Sent change email for %s' % ec.user.email
logger._log(LOGGING_LEVEL, msg, [])
-def activate(user, email_template_name='im/welcome_email.txt'):
+def activate(user, email_template_name='im/welcome_email.txt',
+ helpdesk_email_template_name='im/helpdesk_notification.txt', verify_email=False):
"""
Activates the specific user and sends email.
Raises SendGreetingError, ValidationError
"""
user.is_active = True
+ if verify_email:
+ user.email_verified = True
user.save()
+ send_helpdesk_notification(user, helpdesk_email_template_name)
send_greeting(user, email_template_name)
def invite(invitation, inviter, email_template_name='im/welcome_email.txt'):
def __init__(self):
self.message = _('Failed to send change email')
super(ChangeEmailError, self).__init__()
+
+class SendNotificationError(SendMailError):
+ def __init__(self):
+ self.message = _('Failed to send notification email')
+ super(SendNotificationError, self).__init__()