def send_activation_mail(activation_key): template_context = { 'domain': settings.DOMAIN_BACKEND, 'full_name': activation_key.user.get_full_name(), 'activation_url': settings.DOMAIN_BACKEND + reverse('activation', args=[activation_key.key]) } context = { 'subject': _('Activate Your Account'), 'message': _("Mudek\n" "Hello, {full_name}\n" "Activate Your Account = {activation_url}\n").format( full_name=template_context.get('full_name', ''), activation_url=template_context.get('activation_url', '')), 'html_message': render_to_string('mail/activation-mail.html', template_context), 'from_email': settings.DEFAULT_FROM_EMAIL, 'recipient_list': [activation_key.user.email] } send_mail.delay(context, 'activation')
def follow_up_transcript_mail_registra(trans_pk): """ Sends an email to the registra after 30 days of initial request """ transcripts = Transcript.objects.filter(status=TranscriptStatus.PAID)\ .filter(date_created__day=(timezone.now().day - 30 )).all() group = Group.objects.filter(name='Registra Office').first() staffs_list = [email for email in group.staff_set.all()] for transcript in transcripts: context = {'fullname': transcript.request_by.get_full_name()} send_mail.delay("Transcript request Reminder", 'transcript_reminder_registra.html', username=transcript.request_by.username, to_email=staffs_list, context=context) return True
def _send_mail(subject, email, from_email, send_email, html_message, fail_silently=True, immediately=False): site_url = settings.SITE_URL c = { 'content': email, 'site_url': site_url, } email = loader.render_to_string('email/template.html', c) if immediately: from django.core.mail import send_mail try: send_mail(subject, email, from_email, send_email, html_message=email, fail_silently=fail_silently) except: pass else: try: from utilities.tasks import _send_mail as send_mail send_mail.delay(subject, email, from_email, send_email, html_message=email, fail_silently=fail_silently) except: from django.core.mail import send_mail send_mail(subject, email, from_email, send_email, html_message=email, fail_silently=fail_silently)
def follow_up_transcript_mail(trans_pk): """ Sends an email to the transcript office 14 days after the a transcript request is made to remind every staff in the academic office of the the request """ transcripts = Transcript.objects.filter(status=TranscriptStatus.PAID)\ .filter(date_created__year=(timezone.now().year ))\ .filter(date_created__day=(timezone.now().day - 14 )).all() group = Group.objects.get(name='Academic Office') staffs_list = [email for email in group.staff_set.all()] for transcript in transcripts: context = {'fullname': transcript.request_by.get_full_name()} send_mail.delay("Transcript request Reminder", 'transcript_followup.html', username=transcript.request_by.username, to_email=staffs_list, context=context) return True
def send_email_message(email): logger.info("Sent feedback email") # todo via email conversation, save message etc. message_send = send_mail.delay(email.subject, email.message, email.from_email, email.to_emails, fail_silently=False) save_sent_message(message_send) return message_send