This code OpenAI and I struggled to get working for those of you struggling with sendgrid webhook this is gold code no one has it
Save this and run python3 app.py
Data saved to data.txt
U nano 6.2 hook.py
from flask import Flask, request
app = Flask(name)
@app.route(‘/webhook’, methods=[‘POST’])
def webhook():
try:
# Extract the fields you want from the incoming data
from_email = request.form.get(‘from’)
to_email = request.form.get(‘to’)
subject = request.form.get(‘subject’)
text = request.form.get(‘text’)
# Print and save the extracted fields
print(f"From: {from_email}")
print(f"To: {to_email}")
print(f"Subject: {subject}")
print(f"Content: {text}")
with open('data.txt', 'a') as file:
file.write(f"From: {from_email}\n")
file.write(f"To: {to_email}\n")
file.write(f"Subject: {subject}\n")
file.write(f"Content: {text}\n\n")
return "Webhook received successfully", 200
except Exception as e:
return str(e), 400
if name == ‘main’:
host = “0.0.0.0”
port = 5000
print(f"Flask app is running at: http://{host}:{port}")
app.run(host=host, port=port)
PaulBellow
Split this topic
2
A post was merged into an existing topic: This is exciting you have mail 