SMTP eingefügt

This commit is contained in:
Patrick Hangl
2024-01-15 15:00:40 +01:00
parent c5d8f2d6cf
commit 185d75caba
2 changed files with 19 additions and 1 deletions

18
app.py
View File

@@ -1,4 +1,12 @@
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"
message = "test"
app = Flask(__name__)
@@ -16,6 +24,16 @@ def form():
return render_template('form.html')
if request.method == 'POST':
user = request.form['name']
mail = request.form['email']
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'))