47 lines
1.5 KiB
Python
47 lines
1.5 KiB
Python
|
from flask import Flask, render_template, request
|
||
|
import boto3
|
||
|
import logging
|
||
|
logging.basicConfig(level=logging.INFO)
|
||
|
|
||
|
app = Flask(__name__)
|
||
|
|
||
|
@app.route('/', methods=['GET', 'POST'])
|
||
|
def index():
|
||
|
if request.method == 'POST':
|
||
|
name = request.form['name']
|
||
|
phone = request.form['phone']
|
||
|
address = request.form['address']
|
||
|
comments = request.form['comments']
|
||
|
#print(name,phone,address,comments)
|
||
|
message = f"Name:{name}\nPhone:{phone}\nAddress:{address}\nComments:{comments}"
|
||
|
subject=f"Message from {name} CallBack: {phone}"
|
||
|
sendemail(message,subject)
|
||
|
return render_template('greet.html', name=name, phone=phone, address=address, comments=comments)
|
||
|
return render_template('form.html')
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
app.run(debug=True)
|
||
|
def sendemail(body,subject):
|
||
|
logging.info("Sending Email")
|
||
|
boto3.setup_default_session(profile_name='default')
|
||
|
sesclient=boto3.client('ses',region_name="us-east-2")
|
||
|
recipients=['dan@hamik.net']
|
||
|
CHARSET="UTF-8"
|
||
|
response = sesclient.send_email(
|
||
|
Destination={
|
||
|
"ToAddresses":recipients
|
||
|
},
|
||
|
Message= {
|
||
|
"Body": {
|
||
|
"Html": {
|
||
|
"Charset": CHARSET,
|
||
|
"Data": body
|
||
|
}
|
||
|
},
|
||
|
"Subject": {
|
||
|
"Charset": CHARSET,
|
||
|
"Data": subject
|
||
|
},
|
||
|
},
|
||
|
Source='noreply@hamik.net'
|
||
|
)
|