Example #1
0
    def save(self,
             force_insert=False,
             force_update=False,
             using=None,
             update_fields=None):
        if not self.date:
            self.date = timezone.now()
        if self.target.deadline:
            if self.target.deadline < self.date:
                return
        if self.target.category == "recruitment":
            if self.accepted:
                membership, created = Membership.objects.get_or_create(
                    team=self.target.organizing_committee.all()[0],
                    user=self.applicant)
                membership.save()
                self.delete()

            else:
                super(Application, self).save()
        else:
            if not self.pk:
                if self.target.questionaire:
                    self.questionaire = create_answer_set(
                        self.target.questionaire)
                message = MailerMessage()
                message.subject = "Hey hey! Just dropping by to tell you that" + \
                                  str(self.applicant) + " has applied to the event " + \
                                  str(self.target.name) + "\n Please remember to send " \
                                                          "a " \
                                                          "priority list."
                message.from_address = "noreply@eestecnet",
                message.to_address = ", ".join(
                    user.email for user in self.applicant.lc()[0].privileged())
                message.save()
            if self.accepted:
                participation, created = Participation.objects.get_or_create(
                    target=self.target, participant=self.applicant)
                participation.save()
                message = MailerMessage()
                context = {
                    'user': participation.participant,
                    'slug': participation.target.slug,
                }
                body = render_to_string("events/confirmation_email.txt",
                                        context)
                message.subject = "Congratulations! You were accepted to " + \
                                  participation.target.name
                message.content = body
                message.to_address = self.applicant.email
                message.save()
                len(MailerMessage.objects.all())
                logger.info(
                    str(self.applicant) + "was just accepted to " +
                    str(self.target))

                self.delete()
            else:
                super(Application, self).save()
Example #2
0
def send_invoice(invoice, module):
    print "invoice in send_invoice %s" % invoice

    betreff = "Ihre Bestellung: Mentokis %s" % invoice.product.courseevent.title
    url_parms = urllib.urlencode(
        OrderedDict([
            ('tid', invoice.payrexx_tld),
            ('invoice_amount', invoice.amount),
            ('invoice_currency', invoice.currency),
            ('contact_forename', invoice.first_name),
            ('contact_surname', invoice.last_name),
            ('invoice_number', invoice.title),
            ('contact_email', invoice.email),
        ]))

    #url_input = {
    #      'tid': invoice.payrexx_tld,
    #      'invoice_amount' : invoice.amount,
    #      'invoice_currency' : invoice.currency,
    #      'contact_forename': invoice.first_name,
    #      'contact_surname': invoice.last_name,
    #      'invoice_number' : invoice.title,
    #
    #      }

    #url_parms = urllib.urlencode(url_input)
    print url_parms
    context = {
        'site': Site.objects.get_current(),
        'pay_site': settings.PAYREXX_SITE,
        'product': invoice.product,
        'betreff': betreff,
        'invoice': invoice,
        'url_parms': url_parms
    }

    message = get_template('email/invoice/payment_link.html').render(
        Context(context))

    mail_message = MailerMessage()
    mail_message = MailerMessage(
        subject=betreff,
        bcc_address=settings.MENTOKI_COURSE_EMAIL,
        to_address=invoice.email,
        from_address=settings.MENTOKI_COURSE_EMAIL,
        content=
        "Neuer Kunde: Zahlungslink verschickt an %s über %s: Rechnungsnr. %s" %
        (invoice.email, invoice.product.courseevent.title, invoice.invoice_nr),
        html_content=message,
        reply_to=None,
        app='module')
    mail_message.save()

    logger.info("[%s %s %s %s  gesendet an %s" %
                (invoice.product, invoice.email, invoice.invoice_nr,
                 invoice.currency, invoice.email))
    return
Example #3
0
    def send_email_visitor(self):
        # send email to requesting email
        # this method is called with cleaned from data
        subject = "Ihre Nachricht an mentoki"
        to = [self.cleaned_data['email']]
        from_mail = '*****@*****.**'

        # prepare template
        context = {
            'name': self.cleaned_data['name'],
            'email': self.cleaned_data['email'],
            'message': self.cleaned_data['message'],
            'betreff': "Ihre Nachricht",
        }
        message = get_template('email/contact/to_customer.html').render(
            Context(context))
        to_customer = MailerMessage()
        to_customer.subject = "Ihre Nachricht an mentoki"
        to_customer.to_address = self.cleaned_data['email']
        to_customer.from_address = ContactForm.CONTACT_EMAIL
        to_customer.content = ContactForm.OUTGOING
        to_customer.html_content = message
        to_customer.reply_to = ContactForm.CONTACT_EMAIL
        to_customer.app = self.__module__
        to_customer.save()
Example #4
0
def send_email(to_address,
               subject,
               content,
               html_content,
               bcc_address=None,
               attachment=None,
               attachment2=None,
               attachment3=None):
    new_message = MailerMessage()
    new_message.subject = subject
    new_message.to_address = to_address

    if bcc_address:
        new_message.bcc_address = bcc_address

    new_message.from_address = settings.DEFAULT_FROM_EMAIL
    new_message.content = content
    new_message.html_content = html_content
    new_message.cc_address = settings.DEFAULT_CC_EMAIL
    if attachment:
        new_message.add_attachment(attachment)
    if attachment2:
        new_message.add_attachment(attachment2)
    if attachment3:
        new_message.add_attachment(attachment3)
    new_message.app = "our app name"
    new_message.save()
Example #5
0
    def form_valid(self, form):
        user = form.save(commit=False)
        logger.info(str(user) + " registered on the website.")
        user.is_active = False
        user.activation_link = id_generator(30)
        user.first_name = user.first_name.strip()
        user.middle_name = user.middle_name.strip()
        user.last_name = user.last_name.strip()
        user.email = user.email.strip()

        message = MailerMessage()
        context = {
            'site': RequestSite(self.request),
            'user': user,
            'username': get_username(user),
            'secure': self.request.is_secure(),
            "activation_link": user.activation_link
        }
        message.subject = "Registration"
        message.content = render_to_string("account/registration.html",
                                           context)
        message.from_address = "*****@*****.**"
        message.to_address = user.email
        message.save()
        user.save()
        messages.add_message(
            self.request, messages.INFO,
            'Registration successful. Please check your email to complete the process.'
        )
        return super(EestecerCreate, self).form_valid(form)
Example #6
0
def generate_email(to,
                   from_addr,
                   subject,
                   template,
                   html_template,
                   context={},
                   bcc=None,
                   registration=None):
    if registration:
        subject = subject if not registration.test else '***Test*** ' + subject
    context['site_url'] = settings.SITE_URL
    html = render_to_string(html_template, context)
    body = render_to_string(template, context)
    message = MailerMessage(to_address=', '.join(to),
                            from_address=from_addr,
                            subject=subject,
                            content=body,
                            html_content=html)
    if bcc:
        if isinstance(bcc, basestring):
            message.bcc_address = bcc
        elif isinstance(bcc, (list, tuple)):
            message.bcc_address = ', '.join(bcc)


#     msg = EmailMultiAlternatives(subject, body, from_addr, to, bcc)
#     msg.attach_alternative(html, 'text/html')
    return message
Example #7
0
def send_mail(subject, content, from_addres, to_address):
    new_message = MailerMessage()
    new_message.subject = subject
    new_message.content = content
    new_message.from_addres = from_addres
    new_message.to_address = to_address
    new_message.save()
Example #8
0
def send_post_notification(post, thread, courseevent, module):

    course = courseevent.course
    #contributors_ids = Post.objects.contributors_ids(thread=thread)
    #contributors = User.objects.filter(id__in=contributors_ids)

    #for contributor in contributors:
    #    ClassroomNotification.objects.create(
    #        user = contributor,
    #        courseevent=courseevent,
    #        thread = post.thread,
    #        description = "Neuer Post zum Beitrag %s." %
    #            thread.title
    #    )


    thread_emails = \
        list(Post.objects.contributors_emails(thread=thread))
    thread_emails.append(thread.author.email)
    notification_all_emails = \
        list(CourseEventParticipation.objects.forum_notification_all_emails(courseevent=courseevent))
    notification_none_emails = \
        list(CourseEventParticipation.objects.forum_notification_none_emails(courseevent=courseevent))
    teachers_emails = \
        list(CourseOwner.objects.teachers_emails(course=course))
    all_emails = set(thread_emails + teachers_emails + notification_all_emails)
    notifify_emails = all_emails - set(notification_none_emails)
    send_all = (", ".join(notifify_emails))

    context = {
        'site': Site.objects.get_current(),
        'courseevent': courseevent,
        'post': post,
        'thread': thread,
        'betreff': courseevent.email_greeting
    }

    message = get_template('email/forum/newpost.html').render(Context(context))

    mail_message = MailerMessage(subject="%s: Forum" % courseevent.title,
                                 bcc_address=settings.MENTOKI_COURSE_EMAIL,
                                 to_address=send_all,
                                 from_address=settings.MENTOKI_COURSE_EMAIL,
                                 content="Neuer Post zum Beitrag %s" %
                                 thread.title,
                                 html_content=message,
                                 reply_to=None,
                                 app=module)
    mail_message.save()

    logger.info(
        "[%s] [Beitrag %s %s][Post %s %s][Email %s %s]: gesendet an %s" %
        (courseevent, thread.id, thread.title, post.id, post.title,
         mail_message.id, mail_message, send_all))

    return send_all
Example #9
0
def create_mail_message():
    """Here gives email subject , to_address email id , from_address email id , content of messaage , html_contennt of message"""
    new_message = MailerMessage()
    new_message.subject = "My Subject"
    new_message.to_address = "*****@*****.**"
    new_message.from_address = "*****@*****.**"
    new_message.content = "Mail content"
    new_message.html_content = "<h1>Mail Content</h1>"
    new_message.app = "this is test email please ignore."
    new_message.save()
Example #10
0
def sendmail(singername, receiver, title, url, time):
    new_message = MailerMessage()
    new_message.subject = singername + "演唱會資訊 from Hiticket"
    new_message.to_address = receiver
    new_message.bcc_address = ""
    new_message.from_address = "*****@*****.**"
    new_message.content = ""
    new_message.html_content = "哈囉, 有新的一筆關於" + singername + "演唱會的資料如下:<br><br> \n\n  時間:  " + time + "<br>\n  Title:  " + title + "<br>\n  Link:  " + url
    new_message.app = "Name of your App that is sending the email."
    new_message.save()
Example #11
0
def create_mail_message(request):
    new_message = MailerMessage()
    new_message.subject = "My Subject"
    new_message.to_address = "*****@*****.**"
    new_message.bcc_address = "*****@*****.**"
    new_message.from_address = "*****@*****.**"
    new_message.content = "Mail content"
    new_message.html_content = "<h1>Mail Content</h1>"
    new_message.app = "Name of your App that is sending the email."
    new_message.save()

    return render(request, 'index.html')
Example #12
0
def send_work_comment_notification(studentswork, comment, courseevent, module):

    commenters_emails = \
        list(Comment.objects.commentors_emails(studentswork=studentswork))
    workers_emails = \
        list(studentswork.workers_emails())
    notification_all_emails = \
        list(CourseEventParticipation.objects.forum_notification_all_emails(courseevent=courseevent))
    notification_none_emails = \
        list(CourseEventParticipation.objects.forum_notification_none_emails(courseevent=courseevent))
    teachers_emails = \
        list(CourseOwner.objects.teachers_emails(course=courseevent.course))
    all_emails = set(commenters_emails + workers_emails + teachers_emails + notification_all_emails)
    notifify_emails = all_emails - set(notification_none_emails)
    send_all = ", ".join(notifify_emails)

    context = {
        'site': Site.objects.get_current(),
        'courseevent': courseevent,
        'studentswork': studentswork,
        'homework': studentswork.homework,
        'comment': comment,
        'betreff':  courseevent.email_greeting
    }

    message = get_template('email/homework/newcomment.html').render(Context(context))

    mail_message = MailerMessage(
       subject = "%s: Aufgaben" % courseevent.title,
       bcc_address = settings.MENTOKI_COURSE_EMAIL,
       to_address = send_all,
       from_address = settings.MENTOKI_COURSE_EMAIL,
       content = "Neuer Kommentar von %s zur Aufgabe %s" \
                           % (comment.author, studentswork.homework),
       html_content = message,
       reply_to = None,
       app = module
    )

    mail_message.save()

    logger.info("[%s] [Arbeit %s %s][Kommentar %s %s][Email %s %s]: gesendet an %s"
            % (courseevent,
               studentswork.id,
               studentswork.title,
               comment.id,
               comment.title,
               mail_message.id,
               mail_message,
               send_all))

    return send_all
def send_text_email(to,from_addr,subject,body,context={},cc=[],bcc=[],registration=None):
    body = render_to_string(body,context)
    message = MailerMessage(to_address=', '.join(to),from_address=from_addr,subject=subject,content=body)
    if bcc:
        if isinstance(bcc, basestring):
            message.bcc_address = bcc
        elif isinstance(bcc, (list, tuple)):
            message.bcc_address = ', '.join(bcc)
    message.save()
    if registration:
        registration.email_messages.add(message)
        registration.save()
    return message
Example #14
0
def send_greeting_email(instance, **kwargs):
    is_new = kwargs.get('created', None)
    if is_new:
        new_message = MailerMessage()
        new_message.subject = u"Спасибо за регистрацию!"
        new_message.to_address = instance.email
        # new_message.bcc_address = "*****@*****.**"
        new_message.from_address = "*****@*****.**"
        new_message.html_content = render_to_string('email/greeting.html')
        new_message.content = new_message.html_content
        # new_message.app = "Name of your App that is sending the email."
        new_message.do_not_send = True
        new_message.save()
Example #15
0
def send_email(subject,
               message,
               recipients,
               html=False,
               attachments=None,
               order=None):
    """Send emails

    Parameters
    ----------
    subject: str
        The subject of the email
    message: str
        Body of the email
    recipients: list
        An iterable with django users representing the recipients of the email
    html: bool, optional
        Whether the e-mail should be sent in HTML or plain text

    """

    already_emailed = []
    custom_recipient_handler = oseo_settings.get_mail_recipient_handler()
    if custom_recipient_handler is not None:
        logger.debug("Calling custom recipient handler code...")
        handler = utilities.import_callable(custom_recipient_handler)
        final_recipients = handler(subject,
                                   message,
                                   current_recipients=recipients,
                                   order=order)
    else:
        final_recipients = [r.email for r in recipients]
    logger.debug("email recipients: {}".format(final_recipients))
    for address in final_recipients:
        if address != "" and address not in already_emailed:
            msg = MailerMessage(subject=subject,
                                to_address=address,
                                from_address=django_settings.EMAIL_HOST_USER,
                                app="oseoserver")
            if html:
                text_content = html2text(message)
                msg.content = text_content
                msg.html_content = message
            else:
                msg.content = message
            if attachments is not None:
                for a in attachments:
                    msg.add_attachment(a)
            msg.save()
            already_emailed.append(address)
 def _setup_email(self):
     msg = MailerMessage()
     msg.from_address = self.from_address
     msg.to_address = self._get_formatted_recipients(self.to)
     if self.cc:
         msg.cc_address = self._get_formatted_recipients(self.cc)
     full_bcc = self._get_bcc_with_debugging_copy()
     if full_bcc:
         msg.bcc_address = self._get_formatted_recipients(full_bcc)
     msg.subject = self.get_rendered_subject()
     msg.html_content = self.get_rendered_html_body()
     msg.content = self.get_plain_text_body()
     msg.app = self.mail.text_identifier
     return msg
Example #17
0
def send_mail(subject, message, to, sender='*****@*****.**'):
    """
    Send an email
    :param subject: String subject of the email
    :param message: Text body of the email
    :param to: String email receiver
    :param sender: String email sender
    """
    mail = MailerMessage()
    mail.subject = subject
    mail.to_address = to
    mail.from_address = sender
    mail.html_content = message
    mail.app = 'Appetments'
    mail.save()
Example #18
0
def newsletter(request):
    try:
        validate_email(request.POST['mailsub'])
    except ValidationError:
        return redirect("/")
    messages.add_message(
        request, messages.INFO,
        'You have been subscribed. Please check your e-mail and also your spam folder.'
    )
    message = MailerMessage()
    message.subject = ""
    message.content = ""
    message.from_address = request.POST['mailsub']
    message.to_address = "*****@*****.**"
    message.save()
    return redirect("/")
Example #19
0
 def delete(self, using=None):
     if not self.accepted:
         message = MailerMessage()
         context = {
             'user': self.applicant,
         }
         body = render_to_string("events/rejection_email.txt", context)
         message.subject = "Your application to " + self.target.name
         message.content = body
         message.to_address = self.applicant.email
         message.save()
         logger.info(
             str(self.applicant) + "was just rejected from " +
             str(self.target))
         len(MailerMessage.objects.all())
     return super(Application, self).delete(using)
Example #20
0
 def form_valid(self, form):
     logger.info(
         str(self.request.user) +
         " just sent an email to all privileged members of the EESTEC Community: "
         + form.cleaned_data['message'])
     message = MailerMessage()
     message.subject = form.cleaned_data['subject']
     message.content = form.cleaned_data['message']
     message.from_address = "*****@*****.**"
     message.to_address = "*****@*****.**"
     message.bcc_address = ", ".join(
         user.email
         for user in Eestecer.objects.filter(groups__name="Local Admins"))
     message.save()
     messages.add_message(self.request, messages.INFO,
                          "Message will be sent now.")
     return redirect("/")
Example #21
0
    def _new_message() -> ContextManager[MailerMessage]:
        email = MailerMessage()
        email.from_address = settings.DEFAULT_FROM_EMAIL

        try:
            with override(settings.EMAIL_LANGUAGE):
                yield email
        except:
            raise
        else:
            if email.html_content and not email.content:
                email.content = strip_tags(email.html_content)

            if not email.to_address:
                logger.warning('Email %s has not set recipient address.', email.subject)

            email.save()
Example #22
0
 def form_valid(self, form):
     logger.info(
         str(self.request.user) +
         " just sent an email to the whole EESTEC Community: " +
         form.cleaned_data['message'])
     message = MailerMessage()
     message.subject = form.cleaned_data['subject']
     message.content = form.cleaned_data['message']
     message.from_address = "*****@*****.**"
     message.to_address = "*****@*****.**"
     message.bcc_address = ", ".join(
         user.email
         for user in Eestecer.objects.filter(receive_eestec_active=True))
     message.save()
     messages.add_message(self.request, messages.INFO,
                          "Message will be sent now.")
     return redirect("/")
Example #23
0
def send_receipt(order, transaction, user, module):

    #send also email to teacher

    student_email = user.email
    courseproduct = order.courseproduct
    courseevent = courseproduct.courseevent
    teachers_emails = \
        list(CourseOwner.objects.teachers_emails(course=courseevent.course))
    bcc_mentoki = [settings.MENTOKI_COURSE_EMAIL]
    bcc_list = bcc_mentoki + teachers_emails
    bcc_send = ", ".join(bcc_list)
    context = {
        'site': Site.objects.get_current(),
        'order': order,
        'user':user,
        'courseevent':courseevent,
        'transaction': transaction,

    }

    message = get_template('email/payment/receipt.html').render(Context(context))

    mail_message = MailerMessage(
       subject = "Buchungsbestätigung für Ihre Buchung bei Mentoki",
       bcc_address = bcc_send,
       to_address = user.email,
       from_address = settings.MENTOKI_COURSE_EMAIL,
       content = "Buchungsbestätigung für den Mentokikurs %s" % courseproduct.name,
       html_content = message,
       reply_to = settings.MENTOKI_COURSE_EMAIL,
       app = module
    )
    mail_message.save()

    logger.info("Auftrag [%s]: Buchungsbestätigung geschickt an [%s], bcc [%s]"
            % (order.id,
               bcc_send,
               user.email,
               ))
    message_send = True

    return message_send
Example #24
0
    def save(self,
             force_insert=False,
             force_update=False,
             using=None,
             update_fields=None):
        try:
            if self.category == "training":
                message = MailerMessage()
                context = {
                    'user': self.applicant,
                }
                body = render_to_string("events/training_tracker.txt", context)
                message.subject = " ".join(self.organizers.all(
                )) + "organized a training: " + self.target.name + "EOM"
                message.content = "end of message"
                message.to_address = "*****@*****.**"
                message.save()
        except:
            pass

        self.slug = slugify(self.name)
        if (self.feedbacksheet):
            if self.pk:
                # if created
                orig = Event.objects.get(pk=self.pk)
                if orig.feedbacksheet != self.feedbacksheet:
                    #if feedbacksheet has changed
                    for pax in self.participation_set.all():
                        if pax.feedback:
                            pax.feedback.delete()
                        pax.feedback = create_answer_set(self.feedbacksheet)
                        pax.save()
        if (self.questionaire):
            if self.pk:
                orig = Event.objects.get(pk=self.pk)
                if orig.questionaire != self.questionaire:
                    for application in self.applicants.all():
                        application.questionaire = create_answer_set(
                            self.questionaire)
                        application.save()
        super(Event, self).save(force_insert, force_update, using,
                                update_fields)
    def test_mail_sending(self):

        from mailqueue.models import MailerMessage

        new_message = MailerMessage()
        new_message.subject = "Your test worked."
        new_message.to_address = os.environ['EMAIL_TEST_RECIPIENT']

        # if using Google SMTP, the actual from address will be settings.EMAIL_HOST_USER
        new_message.from_address = "*****@*****.**"

        new_message.content = "Your mail was successfully transmitted at {} Z".format(
            datetime.datetime.utcnow())

        # Note: HTML content supersedes plain content on Google messages
        new_message.html_content = "<h1>This is HTML Mail Content</h1><br>{}".format(
            new_message.content)

        new_message.app = "SAM Reports"
        new_message.save()
        assert True  # always passes if it does not crash
Example #26
0
def send_contact_email(contact):
    to_address = settings.CONTACTS_EMAILS
    from_address = contact.email
    content = render_to_string("contacts/email_contact.txt",
                               {'contact': contact})
    subject = render_to_string("contacts/email_contact_subject.txt",
                               {'contact': contact})
    try:
        from mailqueue.models import MailerMessage
        msg = MailerMessage()
        msg.subject = subject
        msg.to_address = ", ".join(to_address)
        msg.from_address = from_address
        msg.content = content
        msg.app = 'Contacto'
        msg.send_mail()
    except ImportError:
        from django.core.mail import EmailMultiAlternatives
        msg = EmailMultiAlternatives(subject, content, from_address,
                                     to_address)
        msg.send()
Example #27
0
def send_announcement(announcement, courseevent, module):
    """
    Send an announcement: it is send to the teachers and the particpants.
    Mentoki is set on CC. Sending uses django-mailqueue, so that send out
    emails are als stored in the database.
    """
    participants_emails = \
        list(CourseEventParticipation.objects.learners_emails(courseevent=courseevent))
    teachers_emails = \
        list(CourseOwner.objects.teachers_emails(course=courseevent.course))
    all_emails = participants_emails + teachers_emails
    send_all = ", ".join(all_emails)

    context = {
        'site': Site.objects.get_current(),
        'courseevent': courseevent,
        'announcement': announcement,
        'owners': courseevent.teachers,
        'betreff': "Neue Nachricht von Mentoki %s" % courseevent.title
    }
    message = get_template('email/announcement/announcement.html').render(
        Context(context))

    mail_message = MailerMessage()

    mail_message.subject = "Neue Nachricht von %s" % courseevent.title
    mail_message.bcc_address = settings.MENTOKI_COURSE_EMAIL
    mail_message.to_address = send_all
    mail_message.from_address = settings.MENTOKI_COURSE_EMAIL
    mail_message.content = "Neue Nachricht von %s and die Teilnehmer" % courseevent.title
    mail_message.html_content = message
    mail_message.reply_to = send_all
    mail_message.app = module

    mail_distributer = send_all
    logger.info("[%s] [Ankündigung %s %s]: als email verschickt an %s" %
                (courseevent, announcement.id, announcement, mail_distributer))
    mail_message.save()
    return mail_distributer
Example #28
0
    def send_email_self(self):
        """
        email is send to mentoki
        """
        context = {
            'name': self.cleaned_data['name'],
            'email': self.cleaned_data['email'],
            'message': self.cleaned_data['message'],
            'betreff': "Nachricht an mentoki",
        }
        message = get_template('email/contact/to_mentoki.html').render(
            Context(context))

        to_mentoki = MailerMessage()
        to_mentoki.subject = "Kontaktanfrage an mentoki"
        to_mentoki.to_address = ContactForm.CONTACT_EMAIL
        to_mentoki.from_address = self.cleaned_data['email']
        to_mentoki.content = ContactForm.INTERNAL
        to_mentoki.html_content = message
        to_mentoki.reply_to = self.cleaned_data['email']
        to_mentoki.app = self.__module__
        to_mentoki.save()
Example #29
0
def send_thread_delete_notification(author, thread, forum, courseevent,
                                    module):

    course = courseevent.course
    teachers_emails = \
        list(CourseOwner.objects.teachers_emails(course=course))
    all_emails = set(teachers_emails + [author.email])
    send_all = ", ".join(all_emails)

    context = {
        'site': Site.objects.get_current(),
        'courseevent': courseevent,
        'author': author,
        'thread': thread,
        'betreff': courseevent.email_greeting
    }

    message = get_template('email/forum/deletedthread.html').render(
        Context(context))

    mail_message = MailerMessage(subject="%s: Forum" % courseevent.title,
                                 bcc_address=settings.MENTOKI_COURSE_EMAIL,
                                 to_address=send_all,
                                 from_address=settings.MENTOKI_COURSE_EMAIL,
                                 content="%s hat seinen Beitrag %s gelöscht" %
                                 (author.username, thread.title),
                                 html_content=message,
                                 reply_to=None,
                                 app=module)

    mail_message.save()

    logger.info(
        "[%s] [Forum %s %s][Beitrag gelöscht %s %s][Email %s %s]: gesendet an %s"
        % (courseevent, forum.id, forum.title, thread.id, thread.title,
           mail_message.id, mail_message, send_all))

    return send_all
Example #30
0
def send_announcement(announcement, courseevent, module):

    participants_emails = \
        list(CourseEventParticipation.objects.learners_emails(courseevent=courseevent))
    teachers_emails = \
        list(CourseOwner.objects.teachers_emails(course=courseevent.course))
    all_emails = participants_emails + teachers_emails
    send_all = ", ".join(all_emails)

    context = {
        'site': Site.objects.get_current(),
        'courseevent': courseevent,
        'announcement': announcement,
        'owners': courseevent.teachers,
        'betreff': courseevent.email_greeting
    }

    message = get_template('email/announcement/announcement.html').render(
        Context(context))

    mail_message = MailerMessage(
        subject=courseevent.email_greeting,
        bcc_address=settings.MENTOKI_COURSE_EMAIL,
        to_address=send_all,
        from_address=settings.MENTOKI_COURSE_EMAIL,
        content="Neue Nachricht von %s an die Teilnehmer" % courseevent.title,
        html_content=message,
        reply_to=send_all,
        app=module)
    mail_message.save()

    logger.info("[%s] [Ankündigung %s %s][Email %s %s]: gesendet an %s" %
                (courseevent, announcement.id, announcement.title,
                 mail_message.id, mail_message, send_all))

    announcement.publish_announcement(mail_distributor=send_all)

    return send_all