Esempio n. 1
0
def _error(template, status, message, traceback, version, prodhook=None):
    """
    Render the error page with the appropiate parameters, notice that
    the notified parameters hast 3 relevant states True/False/None,
    and is a required parameter.
    """
    if in_development():            
        params = {'status': status,
                  'message': message,
                  'traceback': traceback,
                  'version': version,
                  'notified': None}
    else:
        params =  {'message': message,
                   'status': status}        
        if callable(prodhook):
            params['notified'] = prodhook()
        else:
            params['notified'] = None
    params['STATIC'] = maki.CONFIG('templates')['static_url']
    params['_'] = lambda s: s
    return makoutils.direct_render(template, params)
Esempio n. 2
0
def send(from_, to, subject, content, smtpconf=None):
    """
    Send and email, return True/False on Succes/Failure,
    depending on the configuration, any other
    possible error from the SMTP server will raise an Error.
    """
    smtpconf = get_smtp_config(smtpconf)
    log('Sending email', 'EMAIL')
    log("From: %s\n"\
        "To: %s\n"\
        "Subject: %s\n"\
        "Content: %s\n\n" % (from_, to, subject, content), 'EMAIL')
    msg = Message()
    msg['From'] = from_
    msg['To'] = to
    msg['Subject'] = subject
    msg['Content-Type'] = 'text/html'
    msg.set_payload(content)
    msg.set_charset('utf-8')
    # DEBUG
    #log(msg.as_string())
    if smtpconf is None:
        log('Missing required parameters [host, user, passwd]'
            ' please, make sure that you have the right configuration'
            ' in the main config file. Unable to send email.', 'ERROR')
    if in_development():
        return True
    else:
        if smtpconf is None:
            return False
        else: # Finally send!
            server = smtplib.SMTP_SSL(smtpconf['host'])
            server.login(smtpconf['user'], smtpconf['passwd'])
            server.send_message(msg)
            server.quit()
            return True