Esempio n. 1
0
def dynamic_form_send_confirmation_email(form_model, form, advert, request):
    from django.template import Template, Context

    ctx = {"ad": advert, "advert": advert}

    if advert.confirmation_email_subject:
        subject = Template(advert.confirmation_email_subject).render(Context(ctx))
    else:
        subject = advert.title
    if advert.confirmation_email:
        message = Template(advert.confirmation_email).render(Context(ctx))
    else:
        message = render_to_string("dynamic_forms/confirmation_email.txt", ctx)

    new_message = MailerMessage()
    new_message.subject = subject
    new_message.to_address = form.cleaned_data["email"]
    new_message.bcc_address = (
        "%s, [email protected]" % advert.advertiser.roof_contact
    )  # settings.DYNAMIC_FORMS_EMAIL_HIDDEN_RECIPIENTS
    new_message.reply_to = advert.advertiser.email
    new_message.from_address = "*****@*****.**"
    new_message.from_name = "Roof Media"
    new_message.content = ""
    new_message.html_content = message
    new_message.app = "dynamic_forms"
    new_message.save()
Esempio n. 2
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()
Esempio n. 3
0
def dynamic_form_send_download_email(form_model, form, advert, request):
    from content.models import DownloadLink
    import hashlib
    import random

    salt2 = "".join(["{0}".format(random.randrange(10)) for i in range(10)])
    key = hashlib.md5("{0}{1}".format(salt2, advert.file.name)).hexdigest()

    src = "/".join([settings.MEDIA_ROOT, advert.file.name])

    download_root = os.path.join(settings.MEDIA_ROOT, "downloads")
    download_url = os.path.join(settings.MEDIA_URL, "downloads")

    dst = os.path.join(download_root, key + ".pdf")
    dst_url = os.path.join(download_url, key + ".pdf")
    link = DownloadLink(key=key, ad=advert, url=dst_url, filepath=dst)
    site_url = request.build_absolute_uri("/")
    dl_url = site_url[:-1] + dst_url
    request.META["DL_URL"] = dl_url
    ctx = {"dl_url": dl_url, "ad": advert}

    if advert.confirmation_email_subject:
        subject = Template(advert.confirmation_email_subject).render(Context({"ad": advert}))
    else:
        subject = _("Descarga: “%(advert)s”") % {"advert": advert.title}
    if advert.confirmation_email:
        message = Template(advert.confirmation_email).render(Context(ctx))
    else:
        message = render_to_string("dynamic_forms/download_email.txt", ctx)

    new_message = MailerMessage()
    new_message.subject = subject
    new_message.to_address = form.cleaned_data["email"]
    new_message.bcc_address = (
        "%s, [email protected]" % advert.advertiser.roof_contact
    )  # settings.DYNAMIC_FORMS_EMAIL_HIDDEN_RECIPIENTS
    new_message.reply_to = advert.advertiser.email
    new_message.from_address = "*****@*****.**"
    new_message.from_name = "Roof Media"
    new_message.content = ""
    new_message.html_content = message
    new_message.app = "dynamic_forms"
    new_message.save()

    link.save()
    if not os.path.isdir(os.path.dirname(dst)):
        os.makedirs(os.path.dirname(dst))
    os.symlink(src, dst)
Esempio n. 4
0
 def send(msg):
     tos = msg.to + msg.bcc
     for to in tos:
         new_message = MailerMessage()
         new_message.subject = msg.subject
         new_message.to_address = to
         new_message.from_address = msg.from_email
         new_message.content = msg.body
         if len(msg.alternatives) > 0:
             new_message.html_content = msg.alternatives[0][0]
         new_message.reply_to =  next(iter(msg.reply_to or []),None)
         for a in msg.attachments:
             with open(a[0], 'wb') as f:
                 f.write(a[1])
             at = File(open(a[0], 'rb'))
             new_message.add_attachment(at)
         new_message.save()
Esempio n. 5
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()
Esempio n. 6
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