-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathserver.py
54 lines (43 loc) · 1.51 KB
/
server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from flask import Flask, jsonify, request, send_from_directory
from flask_cors import CORS
import json
from datetime import datetime
import os
app = Flask(__name__, static_folder='.')
CORS(app)
# Mock data to simulate Airtable contacts
mock_contacts = [
{"id": "1", "name": "John Doe", "email": "[email protected]"},
{"id": "2", "name": "Jane Smith", "email": "[email protected]"},
{"id": "3", "name": "Bob Johnson", "email": "[email protected]"},
]
# Mock function to simulate getting contacts from Airtable
def get_contacts():
return mock_contacts
# Mock function to simulate sending an email
def send_email(recipient, subject, body):
print(f"Sending email to: {recipient}")
print(f"Subject: {subject}")
print(f"Body: {body}")
return True
@app.route('/')
def serve_index():
return send_from_directory('.', 'index.html')
@app.route('/contacts', methods=['GET'])
def contacts():
return jsonify(get_contacts())
@app.route('/send-email', methods=['POST'])
def send_email_route():
data = request.json
recipient = data.get('recipient')
subject = data.get('subject')
body = data.get('body')
if not all([recipient, subject, body]):
return jsonify({"error": "Missing required fields"}), 400
success = send_email(recipient, subject, body)
if success:
return jsonify({"message": "Email sent successfully"}), 200
else:
return jsonify({"error": "Failed to send email"}), 500
if __name__ == '__main__':
app.run(host='localhost', port=8580, debug=True)