def _send_mail(self, sender, message, to=[], bcc=[]):
     registry = queryUtility(IRegistry)
     settings = registry.forInterface(ISendtoExtensionSettings, check=False)
     subject = settings.email_subject
     body = settings.email_body
     subject = self._repl_interpolation(subject, sender, '')
     body = self._repl_interpolation(body, sender, message)
     mail_host = queryUtility(IMailHost)
     to = [x for x in to if mail_host.validateSingleEmailAddress(x) and x not in bcc]
     bcc = [x for x in bcc if mail_host.validateSingleEmailAddress(x)]
     ptool = getToolByName(self.context, 'plone_utils')
     if not sender:
          ptool.addPortalMessage(_('No sender address provided'), type="error")
          return False
     if not to and not bcc:
          ptool.addPortalMessage(_('No recipients'), type="error")
          return False
     
     registry = queryUtility(IRegistry)
     settings = registry.forInterface(ISendtoExtensionSettings, check=False)
     if not settings.use_mail_for_sender:
         sender = getToolByName(self.context, 'portal_url').getPortalObject().getProperty('email_from_address')
     
     mail_host.secureSend(body, to, sender, subject=subject,
                          mbcc=bcc, subtype='plain', charset='utf-8')
     ptool.addPortalMessage(_('Message sent'))
     return True
 def __call__(self, context):
     portal = getSite()
     
     # have repactha?
     recaptcha = portal.restrictedTraverse('@@captcha/image_tag', None)
     
     terms = [SimpleTerm(u'', translate(_(u'No protection! Risky Bussiness!'),
                                        context=portal.REQUEST)), ]
     if recaptcha:
         try:
             recaptcha()
             terms.append(SimpleTerm(u'collective.recaptcha', translate(_(u'Recaptcha protection'),
                                                                        context=portal.REQUEST)),)
         except ValueError, inst:
             logger.warning("Can't use recaptcha protection. It seems not configured:\n%s" % inst)
 def handleSave(self, action):
     data, errors = self.extractData()
     if errors:
         self.status = self.formErrorsMessage
         return
     changes = self.applyChanges(data)
     IStatusMessage(self.request).addStatusMessage(_(u"Changes saved"),
                                                   "info")
     self.context.REQUEST.RESPONSE.redirect("@@sendto-settings")
    def send(self):
        """Send e-mail to all recipients, loading e-mail from member is needed and doing security check"""
        # first of all: captcha protection if needed
        if self.capcha_enabled():
            if not self.context.restrictedTraverse('@@captcha').verify():
                ptool = getToolByName(self.context, 'plone_utils') 
                ptool.addPortalMessage(_('Captcha protection code is wrong. Please retry'), type="error")
                return False
        
        form = self.request.form
        sender = form.get('send_from_address', None)
        if not sender and not self.can_set_sender_mail():
            sender = getToolByName(self.context, 'portal_membership').getAuthenticatedMember().getProperty('email')

        message = form.get('message', '')
        send_to_address = form.get('send_to_address', '').strip()
        send_to_address_bcc = form.get('send_to_address_bcc', '').strip()
        if self.can_send_to_multiple_recipients():
            send_to_address = re.findall(r"[\[email protected]_']+", send_to_address)
            send_to_address_bcc = re.findall(r"[\[email protected]_']+", send_to_address_bcc)
        else:
            # whatever we get, it must be a single email address
            send_to_address = [send_to_address]
            send_to_address_bcc = [send_to_address_bcc]

        send_to_members = form.get('send_to_members', [])
        send_to_members_bcc = form.get('send_to_members_bcc', [])
        send_to_groups = form.get('send_to_groups', [])
        send_to_groups_bcc = form.get('send_to_groups_bcc', [])
        cc_me = form.get('cc_me', False)
        
        # If we have items in both a list and in the bcc version, remove from the list
        send_to_address = [x for x in send_to_address if x not in send_to_address_bcc]
        send_to_members = [x for x in send_to_members if x not in send_to_members_bcc]
        send_to_groups = [x for x in send_to_groups if x not in send_to_groups_bcc]

        # get email from principals
        members_email = self._members_email(send_to_members)
        members_email_bcc = self._members_email(send_to_members_bcc)
        groups_email = self._groups_email(send_to_groups)
        groups_email_bcc = self._groups_email(send_to_groups_bcc)
        if cc_me:
            member = getToolByName(self.context, 'portal_membership').getAuthenticatedMember()
            members_email.append(member.getProperty('email'))

        return self._send_mail(sender=sender,
                               message=message,
                               to=send_to_address + members_email + groups_email,
                               bcc=send_to_address_bcc + send_to_members_bcc + send_to_groups_bcc,
                               )
def translate_default_email_body():
    msg = _('email_body',
             default=u"You received this message because someone visiting the URL ${url} wanted to "
                     u"notify you about the page.\n"
                     u"\n"
                     u"The sender address is ${sender}, and it added this comment:\n"
                     u"\n"
                     u"${comment}\n"
                     u"\n"
                     u"--\n"
                     u"\n"
                     u"${site_name}\n"
                     u"${site_description}\n"
                     u"${site_url}\n")
    return translate(msg, context=getSite().REQUEST)
 def handleCancel(self, action):
     IStatusMessage(self.request).addStatusMessage(_(u"Edit cancelled"),
                                                   "info")
     self.request.response.redirect("%s/%s" % (self.context.absolute_url(),
                                               self.control_panel_view))
def translate_default_email_subject():
    msg = _('email_subject',
            default=u'New message from "${site_name}"')
    return translate(msg, context=getSite().REQUEST)