From 17ff2cca90d2aaee6823226345ba9b4f17a4a392 Mon Sep 17 00:00:00 2001 From: theraghavjuneja Date: Sun, 6 Apr 2025 08:51:05 +0530 Subject: [PATCH] Update url.py --- backend/fastapi-backend/routers/url.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/backend/fastapi-backend/routers/url.py b/backend/fastapi-backend/routers/url.py index a45732f..b8af2d3 100644 --- a/backend/fastapi-backend/routers/url.py +++ b/backend/fastapi-backend/routers/url.py @@ -8,6 +8,8 @@ from fastapi.responses import ( RedirectResponse ) +import smtplib +from email.message import EmailMessage import json import asyncio @@ -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() @@ -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 \ No newline at end of file + # 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)}")