def mailPassword(self, forgotten_userid, REQUEST):
        """ Email a forgotten password to a member.

        o Raise an exception if user ID is not found.
        """
        mtool = getUtility(IMembershipTool)
        member = mtool.getMemberById(forgotten_userid)

        if member is None:
            raise ValueError(
                _(u'The username you entered could not be '
                  u'found.'))

        email = self._getValidEmailAddress(member)

        # Rather than have the template try to use the mailhost, we will
        # render the message ourselves and send it from here (where we
        # don't need to worry about 'UseMailHost' permissions).
        if getattr(self, 'REQUEST', None) is None:
            context = RequestContainer(REQUEST=REQUEST)
            for item in reversed(aq_chain(self)):
                context = aq_base(item).__of__(context)
        else:
            context = self
        method = context.unrestrictedTraverse('password_email')
        kw = {'member': member, 'password': member.getPassword()}

        if getattr(aq_base(method), 'isDocTemp', 0):
            mail_text = method(self, REQUEST, **kw)
        else:
            mail_text = method(**kw)

        host = getUtility(IMailHost)
        try:
            host.send(mail_text, immediate=True)
        except (TypeError, socket.error):
            # fallback for mail hosts that don't implement the new signature
            # fallback to queue if immediate fails
            host.send(mail_text)

        try:
            # BBB: for CMF 2.2's mail_password script
            return context.mail_password_response(self, REQUEST)
        except AttributeError:
            pass
    def mailPassword(self, forgotten_userid, REQUEST):
        """ Email a forgotten password to a member.

        o Raise an exception if user ID is not found.
        """
        mtool = getUtility(IMembershipTool)
        member = mtool.getMemberById(forgotten_userid)

        if member is None:
            raise ValueError(_(u'The username you entered could not be '
                               u'found.'))

        email = self._getValidEmailAddress(member)

        # Rather than have the template try to use the mailhost, we will
        # render the message ourselves and send it from here (where we
        # don't need to worry about 'UseMailHost' permissions).
        if getattr(self, 'REQUEST', None) is None:
            context = RequestContainer(REQUEST=REQUEST)
            for item in reversed(aq_chain(self)):
                context = aq_base(item).__of__(context)
        else:
            context = self
        method = context.unrestrictedTraverse('password_email')
        kw = {'member': member, 'password': member.getPassword()}

        if getattr(aq_base(method), 'isDocTemp', 0):
            mail_text = method(self, REQUEST, **kw)
        else:
            mail_text = method(**kw)

        host = getUtility(IMailHost)
        try:
            host.send(mail_text, immediate=True)
        except (TypeError, socket.error):
            # fallback for mail hosts that don't implement the new signature
            # fallback to queue if immediate fails
            host.send(mail_text)

        try:
            # BBB: for CMF 2.2's mail_password script
            return context.mail_password_response(self, REQUEST)
        except AttributeError:
            pass
    def registeredNotify(self, new_member_id, password=None, REQUEST=None):
        """ Handle mailing the registration / welcome message.
        """
        if REQUEST is None:
            raise ValueError(u"'REQUEST' argument is missing.")

        mtool = getUtility(IMembershipTool)
        member = mtool.getMemberById(new_member_id)

        if member is None:
            raise ValueError(
                _(u'The username you entered could not be '
                  u'found.'))

        if password is None:
            password = member.getPassword()

        email = self._getValidEmailAddress(member)

        # Rather than have the template try to use the mailhost, we will
        # render the message ourselves and send it from here (where we
        # don't need to worry about 'UseMailHost' permissions).
        if getattr(self, 'REQUEST', None) is None:
            context = RequestContainer(REQUEST=REQUEST)
            for item in reversed(aq_chain(self)):
                context = aq_base(item).__of__(context)
        else:
            context = self
        method = context.unrestrictedTraverse('registered_email')
        kw = {'member': member, 'password': password, 'email': email}

        if getattr(aq_base(method), 'isDocTemp', 0):
            mail_text = method(self, REQUEST, **kw)
        else:
            mail_text = method(**kw)

        host = getUtility(IMailHost)
        try:
            host.send(mail_text, immediate=True)
        except (TypeError, socket.error):
            # fallback for mail hosts that don't implement the new signature
            # fallback to queue if immediate fails
            host.send(mail_text)
    def registeredNotify(self, new_member_id, password=None, REQUEST=None):
        """ Handle mailing the registration / welcome message.
        """
        if REQUEST is None:
            raise ValueError(u"'REQUEST' argument is missing.")

        mtool = getUtility(IMembershipTool)
        member = mtool.getMemberById(new_member_id)

        if member is None:
            raise ValueError(_(u'The username you entered could not be '
                               u'found.'))

        if password is None:
            password = member.getPassword()

        email = self._getValidEmailAddress(member)

        # Rather than have the template try to use the mailhost, we will
        # render the message ourselves and send it from here (where we
        # don't need to worry about 'UseMailHost' permissions).
        if getattr(self, 'REQUEST', None) is None:
            context = RequestContainer(REQUEST=REQUEST)
            for item in reversed(aq_chain(self)):
                context = aq_base(item).__of__(context)
        else:
            context = self
        method = context.unrestrictedTraverse('registered_email')
        kw = {'member': member, 'password': password, 'email': email}

        if getattr(aq_base(method), 'isDocTemp', 0):
            mail_text = method(self, REQUEST, **kw)
        else:
            mail_text = method(**kw)

        host = getUtility(IMailHost)
        try:
            host.send(mail_text, immediate=True)
        except (TypeError, socket.error):
            # fallback for mail hosts that don't implement the new signature
            # fallback to queue if immediate fails
            host.send(mail_text)