def send(self, action, message, recipients):
     """ send the notifications
     """
     mailhost = getToolByName(self.context, 'MailHost')
     portal = getToolByName(self.context, 'portal_url').getPortalObject()
     mfrom = '%s <%s>' % (portal.getProperty('email_from_name', ''), portal.getProperty('email_from_address', ''))
     #subject = translate(_('email_subject', default='New notification from ${site}', mapping={'site': portal.getProperty('title', '')}), context=self.context.request)
     subject = translate(_('email_subject', default='New notification from ${site}', mapping={'site': portal.getProperty('title', '')}), context=self.context.REQUEST)
     wftool = getToolByName(self.context, 'portal_workflow')
     utils = getToolByName(self.context, 'plone_utils')
     mship = getToolByName(self.context, 'portal_membership')
     wnutils = getMultiAdapter((self.context, self.context.REQUEST), name=u'workflownotification')
     workflow = wftool.getWorkflowById(wnutils.getWorkflowFor(self.context))
     tdef = workflow.transitions.get(action, None)
     if not tdef:
         return
     issuer = mship.getMemberInfo()
     if not issuer:
         issuer = {'username': '******'}
     replacement = dict(name='',
                        title=self.context.Title(),
                        url=self.context.absolute_url(),
                        #old_state=translate(_p(utils.getReviewStateTitleFor(self.context)), context=self.context.request),
                        #new_state=translate(_p(wftool.getTitleForStateOnType(tdef.new_state_id, self.context.portal_type)), context=self.context.request),
                        #transition=translate(_p(tdef.actbox_name), context=self.context.request),
                        old_state=translate(_p(utils.getReviewStateTitleFor(self.context)), context=self.context.REQUEST),
                        new_state=translate(_p(wftool.getTitleForStateOnType(tdef.new_state_id, self.context.portal_type)), context=self.context.REQUEST),
                        transition=translate(_p(tdef.actbox_name), context=self.context.REQUEST),
                        issuer=safe_unicode(issuer.get('fullname', issuer['username'])))
     try:
         anon_message = message % replacement
     except:
         # replacement failed
         anon_message = message
     sent = []
     receivers = []
     for r in recipients:
         replacement.update(dict(name=r.name))
         try:
             msg = message % replacement
         except:
             # replacement failed
             msg = message
         if not r.email in sent:
             mailhost.send(msg,
                           mto=r.email,
                           mfrom=mfrom,
                           subject=subject,
                           charset='utf-8')
             sent.append(r.email)
             receivers.append(r)
     return receivers, anon_message
 def action_send(self, action, data):
     """Send the notification
     """
     sender = INotificationSender(self.context)
     recipients = self.recipients
     for userid in data['users']:
         recipients.append(UserRecipientFactory(userid))
     groups = getToolByName(aq_inner(self.context), 'portal_groups')
     for groupid in data['groups']:
         group = groups.getGroupById(groupid)
         users = group.getGroupMemberIds()
         for userid in users:
             recipients.append(UserRecipientFactory(userid))
     receivers, message = sender.send(self.workflow_action, data['message'], recipients)
     receivers = ', '.join([r.name for r in receivers])
     
     statusmessages = IStatusMessage(self.request)
     statusmessages.addStatusMessage(_('message_success', default='Notifications successfully sent to ${receivers}', mapping={'receivers': receivers}), type='info')
     
     return self.context.content_status_modify(workflow_action=self.workflow_action, comment='', notified=True)