예제 #1
0
    def sendMail(self, action):
        """Send the email to the site administrator and redirect to the
        front page, showing a status message to say the message was received.
        """

        data, errors = self.extractData()
        if errors:
            self.status = self.formErrorsMessage
            return


        elif 'leaveblank' in data and data['leaveblank']:

            urltool = getToolByName(self.context, 'portal_url')

            portal = urltool.getPortalObject()

            self.request.response.redirect(portal.absolute_url())
            return

        else:

            mailhost = getToolByName(self.context, 'MailHost')
            urltool = getToolByName(self.context, 'portal_url')

            portal = urltool.getPortalObject()

            # Construct and send a message
            toAddress = portal.getProperty('email_from_address')
            source = "%s" % (data['emailAddress'])
            subject = "%s  %s %s" % ('Asking for an Account on this Site from', data['firstname'], data['name'])
            message = MESSAGE_TEMPLATE % data

            mailhost.send(message, mto=toAddress, mfrom=str(source), subject=subject, charset='utf8')

            # Issue a status message
            confirm = _(u"Thank you! Your request for an account has been received and we will create an account. You will get an email with a link to activate your account and reset the password.")
            IStatusMessage(self.request).add(confirm, type='info')

            # Redirect to the portal front page. Return an empty string as the
            # page body - we are redirecting anyway!
            self.request.response.redirect(portal.absolute_url())
            return ''
예제 #2
0
def validateEmail(value):
    if not checkEmail(value):
        raise Invalid(_(u"Invalid email address"))
    return True