Example #1
0
        def sendNotificationMail(followerId):
            toOwner = True if followerId == convOwnerId else False
            follower = entities[followerId].basic
            mailId = follower.get('emailId', None)
            if not mailId:
                return defer.succeed(None)

            # Sending to conversation owner
            if toOwner:
                if not settings.getNotifyPref(follower.get('notify', ''),
                                              getattr(settings, notifyAttrOwner),
                                              settings.notifyByMail):
                    return

                subject, body, html = plugin.render(parts, value,
                                                    toOwner=True, data=kwargs)
                subject = "[%s] %s" % (brandName, subject)

            # Sending to others
            else:
                if not settings.getNotifyPref(follower.get('notify', ''),
                                              getattr(settings, notifyAttrOther),
                                              settings.notifyByMail):
                    return

                if not otherStringCache:
                    subject, body, html = plugin.render(parts, value, data=kwargs)
                    subject = "[%s] %s" % (brandName, subject)
                    otherStringCache.extend([subject, body, html])

                subject, body, html = otherStringCache

            return utils.sendmail(mailId, subject, body, html)
Example #2
0
    def notifyOtherUpdate(self, recipients, parts, value, **kwargs):
        notifyType = parts[1]
        plugin = _notificationPlugins.get(notifyType, None)
        if not plugin:
            return

        subject, body, html = plugin.render(parts, value, data=kwargs)

        # Sent the mail if recipient prefers to get it.
        deferreds = []
        entities = kwargs['entities']
        prefAttr = getattr(settings, 'notify'+notifyType)
        prefMedium = settings.notifyByMail
        for userId in recipients:
            user = entities[userId].basic
            mailId = user.get('emailId', None)
            sendMail = settings.getNotifyPref(user.get("notify", ''),
                                              prefAttr, prefMedium)
            if sendMail and mailId:
                fromName = kwargs.get('_fromName', None) or 'Flocked-in'
                deferreds.append(utils.sendmail(mailId, subject,
                                                body, html, fromName=fromName))

        yield defer.DeferredList(deferreds)