#!/usr/bin/python

import sys, json, smtplib
from email.mime.text import MIMEText

eomail = 'info@andreamichaelartist.com'
subject = 'Website Enquiry'


result = {'success' : 'true'}

try:
    input = json.load(sys.stdin)
    print >> sys.stderr, "Sending email to eo from", input['email']
    msg = MIMEText(input['enquiry'])
    msg['Subject'] = subject
    msg['From'] = input['email']
    msg['To'] = eomail
    print >> sys.stderr, "sending email", msg.as_string()
    s = smtplib.SMTP('127.0.0.1')
    s.sendmail(input['email'], [eomail], msg.as_string())
    s.quit() 
    print >> sys.stderr, "sent email", msg.as_string()
except Exception, e:
    print >> sys.stderr, "Failed to send email", e
    result['success'] = 'false'

print 'Content-Type: application/json\n\n'
print json.dumps(result);

