Artisteve commited on
Commit
b87bf91
·
1 Parent(s): c6ac948

Created the application main file

Browse files
Files changed (3) hide show
  1. Dockerfile +13 -0
  2. main.py +54 -0
  3. requirements.txt +3 -0
Dockerfile ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.9
2
+
3
+ RUN useradd -m -u 1000 user
4
+ USER user
5
+ ENV PATH="/home/user/.local/bin:$PATH"
6
+
7
+ WORKDIR /app
8
+
9
+ COPY --chown=user ./requirements.txt requirements.txt
10
+ RUN pip install --no-cache-dir --upgrade -r requirements.txt
11
+
12
+ COPY --chown=user . /app
13
+ CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
main.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI, HTTPException
2
+ from fastapi.middleware.cors import CORSMiddleware
3
+ from pydantic import BaseModel
4
+ import smtplib
5
+ from email.mime.text import MIMEText
6
+ from email.mime.multipart import MIMEMultipart
7
+
8
+
9
+ app = FastAPI()
10
+
11
+ # Configure CORS
12
+ app.add_middleware(
13
+ CORSMiddleware,
14
+ allow_origins=["*"], # Allows all origins
15
+ allow_credentials=True,
16
+ allow_methods=["*"], # Allows all methods
17
+ allow_headers=["*"], # Allows all headers
18
+ )
19
+
20
+ class EmailRequest(BaseModel):
21
+ name: str
22
+ email: str
23
+ subject: str
24
+ message: str
25
+
26
+ @app.post("/send-email")
27
+ async def send_email(email_request: EmailRequest):
28
+ smtp_provider = "smtp.gmail.com"
29
+ smtp_port = 587
30
+ user_email = "[email protected]"
31
+ app_password = "jdypejysxkhebdgo"
32
+ recipient = "[email protected]"
33
+
34
+ try:
35
+ # Create the email
36
+ msg = MIMEMultipart()
37
+ msg['From'] = email_request.email
38
+ msg['To'] = recipient
39
+ msg['Subject'] = email_request.subject
40
+
41
+ body = f"Name: {email_request.name}\nEmail: {email_request.email}\n\n{email_request.message}"
42
+ msg.attach(MIMEText(body, 'plain'))
43
+
44
+ # Send the email
45
+ server = smtplib.SMTP(smtp_provider, smtp_port)
46
+ server.starttls()
47
+ server.login(user_email, app_password)
48
+ text = msg.as_string()
49
+ server.sendmail(user_email, recipient, text)
50
+ server.quit()
51
+
52
+ return {"message": "Email sent successfully!"}
53
+ except Exception as e:
54
+ raise HTTPException(status_code=500, detail=f"Failed to send email: {str(e)}")
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ fastapi
2
+ uvicorn
3
+ fastapi-cors