40 lines
1.1 KiB
Python
40 lines
1.1 KiB
Python
from flask import Flask, request, render_template
|
|
import smtplib
|
|
from email.message import EmailMessage
|
|
|
|
app = Flask(__name__)#
|
|
|
|
@app.route('/')
|
|
def home():
|
|
return render_template('index.html')
|
|
|
|
@app.route('/kontakt', methods=['GET', 'POST'])
|
|
def kontakt():
|
|
if request.method == 'POST':
|
|
name = request.form['name']
|
|
nachricht = request.form['nachricht']
|
|
|
|
# ✉️ E-Mail vorbereiten
|
|
empfaenger = "tdpain5@gmail.com"
|
|
absender = "noreply@example.com"
|
|
passwort = "DEIN_APP_PASSWORT"
|
|
|
|
msg = EmailMessage()
|
|
msg['Subject'] = f"Neue Nachricht von {name}"
|
|
msg['From'] = absender
|
|
msg['To'] = empfaenger
|
|
msg.set_content(nachricht)
|
|
|
|
# 📤 E-Mail senden
|
|
try:
|
|
with smtplib.SMTP_SSL('smtp.gmail.com', 465) as smtp:
|
|
smtp.login(absender, passwort)
|
|
smtp.send_message(msg)
|
|
return "E-Mail erfolgreich gesendet!"
|
|
except Exception as e:
|
|
return f"Fehler beim Senden: {e}"
|
|
|
|
return render_template('contact.html')
|
|
|
|
if __name__ == '__main__':
|
|
app.run(host='0.0.0.0', port=5000, debug=True) |