Spaces:
Runtime error
Runtime error
ReySajju742
commited on
Upload 4 files
Browse files- .env +11 -0
- Dockerfile.txt +17 -0
- app.py +68 -68
- requirements.txt +4 -0
.env
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# .env file
|
2 |
+
|
3 |
+
FLASK_APP=app.py
|
4 |
+
FLASK_ENV=development
|
5 |
+
|
6 |
+
MAIL_SERVER=smtp.example.com # Your email server (e.g., smtp.gmail.com)
|
7 |
+
MAIL_PORT=587 # Port for TLS
|
8 |
+
MAIL_USE_TLS=True # Use TLS
|
9 |
+
MAIL_USERNAME=your_email@example.com # Your email address
|
10 |
+
MAIL_PASSWORD=your_password # Your email password
|
11 |
+
MAIL_DEFAULT_SENDER=your_email@example.com # Default sender email
|
Dockerfile.txt
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Use an official Python runtime as a parent image
|
2 |
+
FROM python:3.9-slim
|
3 |
+
|
4 |
+
# Set the working directory to /app
|
5 |
+
WORKDIR /app
|
6 |
+
|
7 |
+
# Copy the current directory contents into the container at /app
|
8 |
+
COPY . /app
|
9 |
+
|
10 |
+
# Install any needed packages specified in requirements.txt
|
11 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
12 |
+
|
13 |
+
# Expose the port the app runs on
|
14 |
+
EXPOSE 5000
|
15 |
+
|
16 |
+
# Run the app using Gunicorn
|
17 |
+
CMD ["gunicorn", "-b", "0.0.0.0:5000", "app:app"]
|
app.py
CHANGED
@@ -1,68 +1,68 @@
|
|
1 |
-
from flask import Flask, render_template, request, redirect, url_for, flash
|
2 |
-
import requests
|
3 |
-
import os
|
4 |
-
|
5 |
-
app = Flask(__name__)
|
6 |
-
app.secret_key = 'your_secret_key' # Change this to a random secret key
|
7 |
-
|
8 |
-
# Set up your Brevo API key
|
9 |
-
BREVO_API_KEY = "xsmtpsib-9f5b29b661acc0243d2132c93d8ab4024cce4f3011b41a29e72744e21c1ce45b-B1HmQjL72G36FcKS"
|
10 |
-
|
11 |
-
def send_email_via_brevo(to_email, subject, body):
|
12 |
-
url = "https://api.brevo.com/v3/smtp/email"
|
13 |
-
headers = {
|
14 |
-
"accept": "application/json",
|
15 |
-
"content-type": "application/json",
|
16 |
-
"api-key": BREVO_API_KEY
|
17 |
-
}
|
18 |
-
data = {
|
19 |
-
"sender": {"name": "Your Name", "email": "remproduction786@gmail.com"},
|
20 |
-
"to": [{"email": to_email}],
|
21 |
-
"subject": subject,
|
22 |
-
"textContent": body
|
23 |
-
}
|
24 |
-
response = requests.post(url, headers=headers, json=data)
|
25 |
-
return response.status_code, response.json()
|
26 |
-
|
27 |
-
@app.route('/')
|
28 |
-
def home():
|
29 |
-
return render_template('contact_form.html')
|
30 |
-
|
31 |
-
@app.route('/send', methods=['POST'])
|
32 |
-
def send_email():
|
33 |
-
first_name = request.form['firstName']
|
34 |
-
last_name = request.form['lastName']
|
35 |
-
email = request.form['email']
|
36 |
-
event_type = request.form['eventType']
|
37 |
-
event_details = request.form['eventDetails']
|
38 |
-
|
39 |
-
# Construct the email content
|
40 |
-
subject = 'New Contact Form Submission'
|
41 |
-
body = f'''
|
42 |
-
New contact form submission:
|
43 |
-
|
44 |
-
First Name: {first_name}
|
45 |
-
Last Name: {last_name}
|
46 |
-
Email: {email}
|
47 |
-
Event Type: {event_type}
|
48 |
-
Event Details: {event_details}
|
49 |
-
'''
|
50 |
-
|
51 |
-
# Send the email using Brevo
|
52 |
-
status_code, response_data = send_email_via_brevo(
|
53 |
-
to_email="sajjadr742@gmail.com", # Admin email
|
54 |
-
subject=subject,
|
55 |
-
body=body
|
56 |
-
)
|
57 |
-
|
58 |
-
# Check the response status
|
59 |
-
if status_code == 201:
|
60 |
-
flash('Message sent successfully!', 'success')
|
61 |
-
else:
|
62 |
-
flash('Message could not be sent. Please try again later.', 'error')
|
63 |
-
print(response_data) # Print error details for debugging
|
64 |
-
|
65 |
-
return redirect(url_for('home'))
|
66 |
-
|
67 |
-
if __name__ == '__main__':
|
68 |
-
app.run(debug=True)
|
|
|
1 |
+
from flask import Flask, render_template, request, redirect, url_for, flash
|
2 |
+
import requests
|
3 |
+
import os
|
4 |
+
|
5 |
+
app = Flask(__name__)
|
6 |
+
app.secret_key = 'your_secret_key' # Change this to a random secret key
|
7 |
+
|
8 |
+
# Set up your Brevo API key
|
9 |
+
BREVO_API_KEY = "xsmtpsib-9f5b29b661acc0243d2132c93d8ab4024cce4f3011b41a29e72744e21c1ce45b-B1HmQjL72G36FcKS"
|
10 |
+
|
11 |
+
def send_email_via_brevo(to_email, subject, body):
|
12 |
+
url = "https://api.brevo.com/v3/smtp/email"
|
13 |
+
headers = {
|
14 |
+
"accept": "application/json",
|
15 |
+
"content-type": "application/json",
|
16 |
+
"api-key": BREVO_API_KEY
|
17 |
+
}
|
18 |
+
data = {
|
19 |
+
"sender": {"name": "Your Name", "email": "remproduction786@gmail.com"},
|
20 |
+
"to": [{"email": to_email}],
|
21 |
+
"subject": subject,
|
22 |
+
"textContent": body
|
23 |
+
}
|
24 |
+
response = requests.post(url, headers=headers, json=data)
|
25 |
+
return response.status_code, response.json()
|
26 |
+
|
27 |
+
@app.route('/')
|
28 |
+
def home():
|
29 |
+
return render_template('contact_form.html')
|
30 |
+
|
31 |
+
@app.route('/send', methods=['POST'])
|
32 |
+
def send_email():
|
33 |
+
first_name = request.form['firstName']
|
34 |
+
last_name = request.form['lastName']
|
35 |
+
email = request.form['email']
|
36 |
+
event_type = request.form['eventType']
|
37 |
+
event_details = request.form['eventDetails']
|
38 |
+
|
39 |
+
# Construct the email content
|
40 |
+
subject = 'New Contact Form Submission'
|
41 |
+
body = f'''
|
42 |
+
New contact form submission:
|
43 |
+
|
44 |
+
First Name: {first_name}
|
45 |
+
Last Name: {last_name}
|
46 |
+
Email: {email}
|
47 |
+
Event Type: {event_type}
|
48 |
+
Event Details: {event_details}
|
49 |
+
'''
|
50 |
+
|
51 |
+
# Send the email using Brevo
|
52 |
+
status_code, response_data = send_email_via_brevo(
|
53 |
+
to_email="sajjadr742@gmail.com", # Admin email
|
54 |
+
subject=subject,
|
55 |
+
body=body
|
56 |
+
)
|
57 |
+
|
58 |
+
# Check the response status
|
59 |
+
if status_code == 201:
|
60 |
+
flash('Message sent successfully!', 'success')
|
61 |
+
else:
|
62 |
+
flash('Message could not be sent. Please try again later.', 'error')
|
63 |
+
print(response_data) # Print error details for debugging
|
64 |
+
|
65 |
+
return redirect(url_for('home'))
|
66 |
+
|
67 |
+
if __name__ == '__main__':
|
68 |
+
app.run(debug=True)
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Flask==2.3.2 # Flask framework
|
2 |
+
Flask-Mail==0.9.1 # Extension for sending emails
|
3 |
+
python-dotenv==1.0.0 # Load environment variables from a .env file
|
4 |
+
gunicorn==22.0.0
|