Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion backend/fastapi-backend/routers/url.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from fastapi.responses import (
RedirectResponse
)
import smtplib
from email.message import EmailMessage

import json
import asyncio
Expand All @@ -20,7 +22,12 @@
import uuid
import cv2
import os
from dotenv import load_dotenv
load_dotenv()
EMAIL_USER = os.getenv("EMAIL_USER")
EMAIL_PASS = os.getenv("EMAIL_PASS")
from models.question_generate_model import QuestionGenerationRequest
from models.mailrouter import EmailRequest
PDF_STORAGE_DIR="uploaded_pdfs"
os.makedirs(PDF_STORAGE_DIR,exist_ok=True)
router = APIRouter()
Expand Down Expand Up @@ -158,4 +165,21 @@ def extract_text():
# "class_level": request.class_level,
# "chapter_background": request.chapter_background
# }
# this text along with input stuff will be passed to the llm
# this text along with input stuff will be passed to the llm
### MAIL SENDING SERVICE
@router.post("/send-mail")
def send_mail(req: EmailRequest):
try:
msg = EmailMessage()
msg['Subject'] = req.subject
msg['From'] = EMAIL_USER
msg['To'] = req.to
msg.set_content(req.body)
with smtplib.SMTP_SSL('smtp.gmail.com', 465) as smtp:
smtp.login(EMAIL_USER, EMAIL_PASS)
smtp.send_message(msg)

return {"status": "sent"}

except Exception as e:
raise HTTPException(status_code=500, detail=f"Email failed: {str(e)}")