# -*- coding: utf-8 -*- from django.template.loader import render_to_string from django.core.mail import EmailMessage from django.conf import settings from celery.decorators import task SUPPORT_EMAIL = getattr(settings, 'SUPPORT_EMAIL', '') @task def send_registration_email(user_email, confirm_url): """Отправить письмо о регистрации нового пользователя.""" template_name = 'myauth/registration_email.txt' subject = u'Регистрация на Документоре: подтверждение e-mail' dict_context = {'user_email': user_email, 'confirm_url': confirm_url, 'support_email': SUPPORT_EMAIL,} email_body = render_to_string(template_name, dict_context) email = EmailMessage(subject=subject, to=(user_email,), body=email_body) return email.send() @task def send_reset_password_email(user_email, confirm_url): """Отправить письмо с ключём для восстановления пароля.""" template_name = 'myauth/reset_key_email.txt' subject = u'Документор: восстановление пароля' dict_context = {'user_email': user_email, 'confirm_url': confirm_url, 'support_email': SUPPORT_EMAIL,} email_body = render_to_string(template_name, dict_context) email = EmailMessage(subject=subject, to=(user_email,), body=email_body) return email.send() @task def send_new_password_email(user_email, new_password): """Отправить письмо с новым паролем.""" template_name = 'myauth/reset_new_password_email.txt' subject = u'Документор: новый пароль' dict_context = {'user_email': user_email, 'new_password': new_password, 'support_email': SUPPORT_EMAIL,} email_body = render_to_string(template_name, dict_context) email = EmailMessage(subject=subject, to=(user_email,), body=email_body) return email.send()