Пример #1
0
    def send_email_direction(self, direction_label, message):
        user = get_current_user()

        if user:
            mailer = mail.get_mailer()

            base_url = get_url_service().base_url

            substitutions = {
                u'SENDER': user.email,
                u'FIRSTNAME': user.firstname,
                u'LASTNAME': user.lastname,
                u'IDEA_LINK': self.idea.absolute_url,
                u'IDEA_ID': str(self.idea.id),
                u'DIRECTION_LABEL': direction_label,
                u'MESSAGE': message,
                u'EUREKA_LINK': render_link(_(u'Eurêka'), base_url),
                u'RECIPIENTS': mailer.get_substitutions()[u'DSIG_EMAIL']
            }

            content = _perform_substitutions(
                'mail-idea-duplicated-direction.html', 'fr', substitutions)
            (content, subject, sender, to_recipients, cc_recipients,
             bcc_recipients) = _extract_metadata(content)

            mailer.send_mail(subject,
                             from_=sender,
                             to=to_recipients,
                             cc=cc_recipients,
                             bcc=bcc_recipients,
                             content=content,
                             type='html')
Пример #2
0
    def send_email_direction(self, direction_label, message):
        user = get_current_user()

        if user:
            mailer = mail.get_mailer()

            base_url = get_url_service().base_url

            substitutions = {
                u'SENDER': user.email,
                u'FIRSTNAME': user.firstname,
                u'LASTNAME': user.lastname,
                u'IDEA_LINK': self.idea.absolute_url,
                u'IDEA_ID': str(self.idea.id),
                u'DIRECTION_LABEL': direction_label,
                u'MESSAGE': message,
                u'EUREKA_LINK': render_link(_(u'Eurêka'), base_url),
                u'RECIPIENTS': mailer.get_substitutions()[u'DSIG_EMAIL']
            }

            content = _perform_substitutions(
                'mail-idea-duplicated-direction.html',
                'fr', substitutions)
            (content, subject, sender, to_recipients,
             cc_recipients, bcc_recipients) = _extract_metadata(content)

            mailer.send_mail(subject, from_=sender, to=to_recipients,
                             cc=cc_recipients, bcc=bcc_recipients,
                             content=content, type='html')
Пример #3
0
    def test_cc_recipients(self):
        """
        Test if the 'Cc:' recipients are correctly handled.
        """
        mailer = mail.get_mailer()
        mailer.activated = True
        mailer.smtp_host = '<dummy_host>'
        mailer.smtp_port = 25
        mailer.hidden_recipients = []

        expected_host = mailer.smtp_host
        expected_port = mailer.smtp_port

        # checks with Cc: recipients
        mailer.send_mail('Welcome on board!', 's.d@netng', ['a.b@netng'],
                         'Welcome!', ['c.d@netng', 'e.f@netng'])

        expected_to = ['a.b@netng', 'c.d@netng', 'e.f@netng']
        expected_fields = {'Subject:': 'Welcome on board!',
                           'To:': 'a.b@netng',
                           'Cc:': 'c.d@netng, e.f@netng'}
        self.assert_smtp_send_data_equal('s.d@netng', expected_to, expected_fields, expected_host, expected_port)

        # checks without Cc: recipients
        mailer.send_mail('Welcome on board!', 's.d@netng', ['a.b@netng'], 'Welcome!')

        expected_to = ['a.b@netng']
        expected_fields = {'Subject:': 'Welcome on board!',
                           'To:': 'def1@netng, def2@netng', 'Cc:': None}
def _get_substitutions(to, comment=None, idea=None, fi=None, previous_di=None, comment_author=None, **kw):

    # initialize useful values for substitutions
    base_url = get_url_service().base_url
    shop_url = get_url_service().expand_url(['shop'], relative=False)
    idea_url = get_url_service().expand_url(['idea', idea.id], relative=False) if idea else u''

    fi = fi or (idea.wf_context.assignated_fi if idea else None)
    di = idea.wf_context.assignated_di if idea else None

    mailer = mail.get_mailer()

    # creates the substitutions
    substitutions = {
        u'RECIPIENT_LOGIN': to.uid if to else u'',
        u'RECIPIENT_FIRSTNAME': to.firstname if to else u'',
        u'RECIPIENT_LASTNAME': to.lastname if to else u'',
        u'RECIPIENT_EMAIL': to.email or u'' if to else u'',

        u'FI_FIRSTNAME': fi.firstname if fi else u'',
        u'FI_LASTNAME': fi.lastname if fi else u'',
        u'FI_EMAIL': fi.email if fi and fi.email else u'',

        u'DI_FIRSTNAME': di.firstname if di else u'',
        u'DI_LASTNAME': di.lastname if di else u'',
        u'DI_EMAIL': di.email if di and di.email else u'',

        u'IDEA_ID': str(idea.id) if idea else u'',
        u'IDEA_TITLE': text_to_html(idea.title) if idea else u'',
        u'IDEA_LINK_HERE': render_link(_(u'here'), idea_url),

        u'SUBMISSION_DATE': format_date(datetime.today(), format='medium'),
        u'COMMENT': text_to_html(comment or u''),

        u'COMMENT_AUTHOR_FIRSTNAME': comment_author.firstname if comment_author else '',
        u'COMMENT_AUTHOR_LASTNAME': comment_author.lastname if comment_author else '',

        u'EUREKA_LINK': render_link(_(u'Eurêka'), base_url),
        u'EUREKA_URL_LINK': render_link(base_url, base_url),
        u'SHOP_LINK': render_link(_(u'shop'), shop_url),

        u'PREVIOUS_DI_EMAIL': (previous_di.email if (previous_di and previous_di.email) else u''),
        u'PREVIOUS_DI_FIRSTNAME': (previous_di.firstname if (previous_di and previous_di.firstname) else u''),
        u'PREVIOUS_DI_LASTNAME': (previous_di.lastname if (previous_di and previous_di.lastname) else u''),
    }

    substitutions.update(mailer.get_substitutions())

    substitutions.update({k.upper(): v for k, v in kw.iteritems()})

    return substitutions
Пример #5
0
    def send_email(self):
        properties = ('recipients', 'subject', 'message')
        if not self.user:
            properties += ('sender_email',)

        if not self.is_validated(properties):
            return False  # failure

        recipients = self.recipients.value
        subject = self.subject.value
        message = self.message.value
        sender_email = self.user.email if self.user else self.sender_email.value
        mailer = mail.get_mailer()
        mailer.send_mail(subject=subject, from_=sender_email, to=recipients,
                         content=message)
        return True  # success
Пример #6
0
    def send_email(self):
        properties = ('recipients', 'subject', 'message')
        if not self.user:
            properties += ('sender_email', )

        if not self.is_validated(properties):
            return False  # failure

        recipients = self.recipients.value
        subject = self.subject.value
        message = self.message.value
        sender_email = self.user.email if self.user else self.sender_email.value
        mailer = mail.get_mailer()
        mailer.send_mail(subject=subject,
                         from_=sender_email,
                         to=recipients,
                         content=message)
        return True  # success
Пример #7
0
    def commit(self):
        properties = ('subject', 'message')
        if not self.user:
            properties += ('sender_email',)

        if not self.is_validated(properties):
            return False  # failure

        subject = _(u'Eureka : Contact (%s)') % self.subject()
        message = self.message()

        sender = self.user.email if self.user else self.sender_email.value
        mailer = mail.get_mailer()
        recipient = mailer.support_sender
        mailer.send_mail(subject, sender, [recipient], message)

        confirmation = _(u'Your request has been sent to the IPS team that will answer it as soon as possible')
        flashmessage.set_flash(confirmation)
        event_management._emit_signal(self, "VIEW_FRONTDESK")
        return True  # success
def send(template_filename, to, delivery_priority=DeliveryPriority.Normal, attachments=None, **kw):
    from eureka.domain.models import MailDeliveryFrequency
    from eureka.domain.repositories import UserRepository

    user_repository = UserRepository()

    locale = to.locale if to else 'fr'

    # creates the email contents
    substitutions = _get_substitutions(to=to, **kw)
    content = _perform_substitutions(template_filename, locale, substitutions)

    # extracts and remove the metadata
    content, subject, sender, to_recipients, cc_recipients, bcc_recipients = _extract_metadata(content)

    # attachments
    attachments = attachments or ()

    # if there's no recipient, no need to send an email
    if not to_recipients:
        return

    mailer = mail.get_mailer()

    if (delivery_priority == DeliveryPriority.Normal) or attachments:
        # FIXME: for consistency, we should also send one email per recipient, using the target user locale
        # send now (one message with all the recipients)
        mailer.send_mail(subject, from_=sender, to=to_recipients, cc=cc_recipients, bcc=bcc_recipients,
                         content=content, type='html', attachments=attachments)
    elif delivery_priority == DeliveryPriority.Low:
        # send one message per user (since we need the examine the mail delivery setting of each user)
        for user_email in to_recipients + cc_recipients + bcc_recipients:
            user = user_repository.get_by_email(unicode(user_email))
            send_now = not user or user.mail_delivery_frequency == MailDeliveryFrequency.Immediately

            if send_now:
                # sends the email now
                mailer.send_mail(subject, from_=sender, to=[user_email], content=content, type='html')
            else:
                # add the message to the user's pending email messages
                user.add_pending_email_message(subject, content)
Пример #9
0
    def commit(self):
        properties = ('subject', 'message')
        if not self.user:
            properties += ('sender_email', )

        if not self.is_validated(properties):
            return False  # failure

        subject = _(u'Eureka : Contact (%s)') % self.subject()
        message = self.message()

        sender = self.user.email if self.user else self.sender_email.value
        mailer = mail.get_mailer()
        recipient = mailer.support_sender
        mailer.send_mail(subject, sender, [recipient], message)

        confirmation = _(
            u'Your request has been sent to the IPS team that will answer it as soon as possible'
        )
        flashmessage.set_flash(confirmation)
        event_management._emit_signal(self, "VIEW_FRONTDESK")
        return True  # success
Пример #10
0
    def test_cc_recipients(self):
        """
        Test if the 'Cc:' recipients are correctly handled.
        """
        mailer = mail.get_mailer()
        mailer.activated = True
        mailer.smtp_host = '<dummy_host>'
        mailer.smtp_port = 25
        mailer.hidden_recipients = []

        expected_host = mailer.smtp_host
        expected_port = mailer.smtp_port

        # checks with Cc: recipients
        mailer.send_mail('Welcome on board!', 's.d@netng', ['a.b@netng'],
                         'Welcome!', ['c.d@netng', 'e.f@netng'])

        expected_to = ['a.b@netng', 'c.d@netng', 'e.f@netng']
        expected_fields = {
            'Subject:': 'Welcome on board!',
            'To:': 'a.b@netng',
            'Cc:': 'c.d@netng, e.f@netng'
        }
        self.assert_smtp_send_data_equal('s.d@netng', expected_to,
                                         expected_fields, expected_host,
                                         expected_port)

        # checks without Cc: recipients
        mailer.send_mail('Welcome on board!', 's.d@netng', ['a.b@netng'],
                         'Welcome!')

        expected_to = ['a.b@netng']
        expected_fields = {
            'Subject:': 'Welcome on board!',
            'To:': 'def1@netng, def2@netng',
            'Cc:': None
        }