DhanushMahesh commited on
Commit
24755f7
·
1 Parent(s): c075fed

Add initial implementation of FastAPI application with email service

Browse files
Files changed (4) hide show
  1. Dockerfile +16 -0
  2. app.py +23 -0
  3. requirements.txt +3 -0
  4. service.py +33 -0
Dockerfile ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
2
+ # you will also find guides on how best to write your Dockerfile
3
+
4
+ FROM python:3.9
5
+
6
+ RUN useradd -m -u 1000 user
7
+ USER user
8
+ ENV PATH="/home/user/.local/bin:$PATH"
9
+
10
+ WORKDIR /app
11
+
12
+ COPY --chown=user ./requirements.txt requirements.txt
13
+ RUN pip install --no-cache-dir --upgrade -r requirements.txt
14
+
15
+ COPY --chown=user . /app
16
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
app.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ from service import EmailService
3
+
4
+ app = FastAPI()
5
+
6
+
7
+ @app.post("/check")
8
+ async def check_email_service(
9
+ ):
10
+ try:
11
+ email_service = EmailService()
12
+ await email_service.send_test_email("dhanush@yuvabe.com")
13
+ return {
14
+ "status_code": 200,
15
+ "message": "Test email sent successfully.",
16
+ "data": None,
17
+ }
18
+ except Exception as e:
19
+ return {
20
+ "status_code": 500,
21
+ "message": f"Failed to send test email: {e}",
22
+ "data": None,
23
+ }
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ fastapi
2
+ uvicorn[standard]
3
+ aiosmtplib
service.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from email.message import EmailMessage
2
+ import aiosmtplib
3
+ import os
4
+
5
+
6
+ class EmailService:
7
+ def __init__(self, mail_config: dict | None = None):
8
+ self.mail_config = mail_config or {
9
+ "hostname": "smtp.gmail.com",
10
+ "port": 587,
11
+ "username": "hariprasath137@gmail.com",
12
+ "password": os.getenv("EMAIL_PASSWORD"),
13
+ "start_tls": True,
14
+ }
15
+
16
+ async def send_test_email(self, recipient: str):
17
+ try:
18
+
19
+ message = EmailMessage()
20
+ message["From"] = f"KittyKat Agents <{self.mail_config['username']}>"
21
+ message["To"] = recipient
22
+ message["Subject"] = "Test Email from KittyKat Agents"
23
+ message.set_content(
24
+ "This is a test email to verify the email service is operational.")
25
+ message.add_alternative("<h1>Test</h1>", subtype="html")
26
+
27
+ await aiosmtplib.send(
28
+ message,
29
+ **self.mail_config,
30
+ )
31
+ except Exception as e:
32
+ print(f"Error sending test email: {e}")
33
+ raise e