47 lines
1.3 KiB
Python
47 lines
1.3 KiB
Python
from flask import Flask, render_template, request, redirect, url_for
|
|
import smtplib, ssl
|
|
|
|
port = 587 # For starttls
|
|
smtp_server = "smtp.gmail.com"
|
|
sender_email = "patha9201@gmail.com"
|
|
# receiver_email = "patha9201@gmail.com"
|
|
password = "dqlw ablc clic uvgp"
|
|
|
|
|
|
app = Flask(__name__)
|
|
|
|
@app.route('/', methods=['GET','POST'])
|
|
def home():
|
|
if request.method == 'GET':
|
|
return render_template('index.html')
|
|
if request.method == 'POST':
|
|
return redirect(url_for('form'))
|
|
|
|
|
|
@app.route ('/form', methods=['GET','POST'])
|
|
def form():
|
|
if request.method == 'GET':
|
|
return render_template('form.html')
|
|
if request.method == 'POST':
|
|
receiver = request.form['name']
|
|
receiver_email = request.form['email']
|
|
message = f"Sehr geehrter Herr {receiver},"
|
|
|
|
context = ssl.create_default_context()
|
|
with smtplib.SMTP(smtp_server, port) as server:
|
|
server.ehlo() # Can be omitted
|
|
server.starttls(context=context)
|
|
server.ehlo() # Can be omitted
|
|
server.login(sender_email, password)
|
|
server.sendmail(sender_email, receiver_email, message)
|
|
|
|
return redirect(url_for('submitted'))
|
|
|
|
|
|
@app.route ('/submitted')
|
|
def submitted():
|
|
return render_template('submitted.html')
|
|
|
|
|
|
if __name__ == '__main__':
|
|
app.run(debug=True) |