Skip to content

Commit

Permalink
fix: 🐛 fix timout while sending emails
Browse files Browse the repository at this point in the history
  • Loading branch information
thomashbrnrd committed Oct 4, 2024
1 parent 661fc98 commit 9471ae1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
4 changes: 2 additions & 2 deletions backend/src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import os
import ssl
from datetime import datetime
from smtplib import SMTP

import boto3
from cryptography.hazmat.primitives.serialization import Encoding, PublicFormat
Expand Down Expand Up @@ -131,7 +130,8 @@ def get_base_logs(user_agent, user_id: str) -> dict:
]

# Emails
SMTPClient = SMTP(os.environ["EMAIL_HOST"], os.environ["EMAIL_PORT"])
EMAIL_HOST = os.environ["EMAIL_HOST"]
EMAIL_PORT = os.environ["EMAIL_PORT"]

# Authentication
OIDC_CLIENT_ID = os.environ["OIDC_CLIENT_ID"]
Expand Down
15 changes: 12 additions & 3 deletions backend/src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,22 @@
import time
from datetime import datetime
from email.message import EmailMessage
from smtplib import SMTP
from typing import Annotated

import jwt
from fastapi import Depends, HTTPException, status

from src.config import OIDC_CLIENT_ID, SMTPClient
from src.config import OIDC_CLIENT_ID

from .config import OAUTH2_SCHEME, PUBLIC_KEY, S3, S3_BUCKET_NAME
from .config import (
EMAIL_HOST,
EMAIL_PORT,
OAUTH2_SCHEME,
PUBLIC_KEY,
S3,
S3_BUCKET_NAME,
)


def upload_image(content: bytes, image_key: str):
Expand Down Expand Up @@ -43,7 +51,8 @@ async def send_mail(subject: str, to: str, message: str, attachements: list = []
subtype=attachement.content_type,
filename=attachement.filename,
)
SMTPClient.send_message(msg)
with SMTP(EMAIL_HOST, EMAIL_PORT) as smtp_client:
smtp_client.send_message(msg)


async def get_current_user(token: Annotated[str, Depends(OAUTH2_SCHEME)]):
Expand Down

0 comments on commit 9471ae1

Please sign in to comment.