fromflaskimportFlask,requestimportsimplejsonapp=Flask(__name__)@app.route('/parse',methods=['POST'])defsendgrid_parser():# Consume the entire emailenvelope=simplejson.loads(request.form.get('envelope'))# Get some header informationto_address=envelope['to'][0]from_address=envelope['from']# Now, onto the bodytext=request.form.get('text')html=request.form.get('html')subject=request.form.get('subject')# Process the attachements, if anynum_attachments=int(request.form.get('attachments',0))attachments=[]ifnum_attachments>0:fornuminrange(1,(num_attachments+1)):attachment=request.files.get(('attachment%d'%num))attachments.append(attachment.read())# attachment will have all the parameters expected in a Flask file uploadreturn"OK"if__name__=='__main__':app.run(debug=True)