Ejemplo n.º 1
0
def sendtestemail():
    print "Content-type: text/plain\n"

    logging.basicConfig(filename='../logs/testemail.log', level=logging.DEBUG)
    try:
        conlen = int(os.environ['CONTENT_LENGTH'])
        rawinp = sys.stdin.read(conlen)
    except Exception:
        rawinp = sys.stdin.read()
    print >> sys.stderr, rawinp

    if rawinp == '':
        res = {'status':'Error', 'error': 'No input given.'}
        print json.dumps (res)
        sys.exit()
    data = json.loads(rawinp)

    password = data['password']
    if not access.validPassword(password): access.incorrectPassword()

    emailConfig = data['emailConfig']
    port = emailConfig['email_port']
    if simpleemail.validport(port) != True:
        print json.dumps({'status': 'Error', 'error': simpleemail.validport(port)})
        sys.exit(0)

    emailMsg = data['emailMsg']
    simpleemail.sendemail(emailConfig, emailMsg)
Ejemplo n.º 2
0
        len(fStorage)
    except Exception, err:
        return json.dumps({'status':'Error', 'error': 'No parameters specified.'})

    logging.info(fStorage)
    conf = readConf()
    emailSettings = conf.get('email','')
    if emailSettings == '':
        res = {'status':'Error', 'error': 'Email configuration not set.'}
        return json.dumps(res)

    email_host = emailSettings.get('host','')
    email_port = emailSettings.get('port','')
    e_error = ''
    if email_host == '': e_error = 'SMTP host not set. '
    if simpleemail.validport(email_port) != True:
        e_error += simpleemail.validport(email_port)
    if e_error != '':
        return json.dumps ({'status':'Error', 'error': e_error})

    emailUsername = emailSettings.get('username','')
    emailPassword = emailSettings.get('password','')

    e_error = ''
    #if emailUsername == '' and emailPassword != '':
    #    e_error = 'SMTP username set, but not SMTP password.'
    #if emailPassword == '' and emailUsername != '':
    #    e_error = 'SMTP username not set, but SMTP password is set.'
    if e_error != '':
        return json.dumps ({'status': 'Error', 'error':e_error})