dahyedahye commited on
Commit
dc6f036
Β·
1 Parent(s): b74c144
Files changed (5) hide show
  1. __pycache__/app.cpython-39.pyc +0 -0
  2. app.py +2 -2
  3. app.py.backup +85 -0
  4. requirements.txt +1 -0
  5. tmp.ipynb +105 -0
__pycache__/app.cpython-39.pyc ADDED
Binary file (1.6 kB). View file
 
app.py CHANGED
@@ -33,7 +33,7 @@ executor = ThreadPoolExecutor(max_workers=3) # μ΅œλŒ€ 3개의 μŠ€λ ˆλ“œλ‘œ λΉ„
33
 
34
  def send_email_(to_email: str):
35
  smtp_server = "smtp.gmail.com"
36
- smtp_port = 1025
37
  smtp_user = os.getenv("SMTP_USER")
38
  smtp_password = os.getenv("SMTP_PASSWORD")
39
 
@@ -79,4 +79,4 @@ def send_email(email: str, background_tasks: BackgroundTasks):
79
  return JSONResponse(status_code=202, content={"message": "You will receive an email when it's done."})
80
 
81
  except Exception as e:
82
- raise HTTPException(status_code=500, detail=str(e))
 
33
 
34
  def send_email_(to_email: str):
35
  smtp_server = "smtp.gmail.com"
36
+ smtp_port = 2525
37
  smtp_user = os.getenv("SMTP_USER")
38
  smtp_password = os.getenv("SMTP_PASSWORD")
39
 
 
79
  return JSONResponse(status_code=202, content={"message": "You will receive an email when it's done."})
80
 
81
  except Exception as e:
82
+ raise HTTPException(status_code=500, detail=str(e))
app.py.backup ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # POSTMARK_API_KEY=db96eba8-a4b5-4b83-9377-2e7dcdc00d39
2
+ # SMTP_USER=kyowoon.lee1924@gmail.com
3
+
4
+ import os
5
+ import logging
6
+ import requests
7
+ from concurrent.futures import ThreadPoolExecutor
8
+ from fastapi import FastAPI, HTTPException, BackgroundTasks
9
+ from fastapi.responses import JSONResponse
10
+ from dotenv import load_dotenv
11
+
12
+ # Load environment variables from .env file
13
+ load_dotenv()
14
+
15
+ # Set up logging configuration
16
+ logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')
17
+
18
+ app = FastAPI(
19
+ # version="0.0.1",
20
+ # servers=[
21
+ # {
22
+ # "url": "https://leekwoon-email-api.hf.space",
23
+ # "description": "email API",
24
+ # }
25
+ # ],
26
+ )
27
+
28
+ from postmarker.core import PostmarkClient
29
+ postmark = PostmarkClient(server_token=os.getenv("POSTMARK_API_KEY"))
30
+
31
+ executor = ThreadPoolExecutor(max_workers=3) # μ΅œλŒ€ 3개의 μŠ€λ ˆλ“œλ‘œ 비동기 μž‘μ—… 처리
32
+
33
+ def send_email_(to_email: str):
34
+ # postmark_api_key = os.getenv("POSTMARK_API_KEY")
35
+ from_email = os.getenv("SMTP_USER") # This should be your verified Postmark sender email
36
+
37
+ subject = "[kyobody - μžλ§‰μƒμ„±] μž‘μ—…μ΄ μ™„λ£Œλ˜μ—ˆμŠ΅λ‹ˆλ‹€."
38
+ body = "[kyobody - μžλ§‰μƒμ„±] μž‘μ—…μ΄ μ™„λ£Œλ˜μ—ˆμŠ΅λ‹ˆλ‹€.SRT νŒŒμΌμ„ μ²¨λΆ€ν•˜μ—¬ μ „λ‹¬λ“œλ¦½λ‹ˆλ‹€."
39
+
40
+ postmark.emails.send(
41
+ From=os.getenv("SMTP_USER"),
42
+ To=to_email,
43
+ Subject=subject,
44
+ HtmlBody=body
45
+ )
46
+
47
+ # headers = {
48
+ # "Accept": "application/json",
49
+ # "X-Postmark-Server-Token": postmark_api_key,
50
+ # "Content-Type": "application/json",
51
+ # }
52
+
53
+ # data = {
54
+ # "From": from_email,
55
+ # "To": to_email,
56
+ # "Subject": subject,
57
+ # "TextBody": body,
58
+ # }
59
+
60
+ # try:
61
+ # print('hi')
62
+ # response = requests.post(
63
+ # "https://api.postmarkapp.com/email",
64
+ # headers=headers,
65
+ # json=data
66
+ # )
67
+ # response.raise_for_status() # Raises an HTTPError if the HTTP request returned an unsuccessful status code
68
+ # logging.debug(f"Email successfully sent to {to_email}, Response: {response.json()}")
69
+
70
+ # except requests.exceptions.RequestException as e:
71
+ # # Log any exceptions that occur during the email sending process
72
+ # logging.error(f"Failed to send email to {to_email}: {str(e)}")
73
+ # raise e
74
+
75
+ @app.post("/send-email")
76
+ def send_email(email: str, background_tasks: BackgroundTasks):
77
+ try:
78
+ # Schedule the email sending in the background
79
+ background_tasks.add_task(executor.submit, send_email_, email)
80
+
81
+ # Respond to the client immediately
82
+ return JSONResponse(status_code=202, content={"message": "You will receive an email when it's done."})
83
+
84
+ except Exception as e:
85
+ raise HTTPException(status_code=500, detail=str(e))
requirements.txt CHANGED
@@ -1,3 +1,4 @@
1
  fastapi # FastAPI ν”„λ ˆμž„μ›Œν¬
2
  uvicorn # FastAPI μ„œλ²„ 싀행을 μœ„ν•œ Uvicorn ASGI μ„œλ²„
3
  python-dotenv
 
 
1
  fastapi # FastAPI ν”„λ ˆμž„μ›Œν¬
2
  uvicorn # FastAPI μ„œλ²„ 싀행을 μœ„ν•œ Uvicorn ASGI μ„œλ²„
3
  python-dotenv
4
+ boto3
tmp.ipynb ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 2,
6
+ "metadata": {},
7
+ "outputs": [],
8
+ "source": [
9
+ "import os\n",
10
+ "from postmarker.core import PostmarkClient\n",
11
+ "postmark = PostmarkClient(server_token=os.getenv(\"POSTMARK_API_KEY\"))"
12
+ ]
13
+ },
14
+ {
15
+ "cell_type": "code",
16
+ "execution_count": 5,
17
+ "metadata": {},
18
+ "outputs": [
19
+ {
20
+ "data": {
21
+ "text/plain": [
22
+ "{'ErrorCode': 0,\n",
23
+ " 'Message': 'OK',\n",
24
+ " 'MessageID': 'fad620aa-dbcd-4435-9e93-3ee192c41dbb',\n",
25
+ " 'SubmittedAt': '2024-09-03T09:58:55.9467739Z',\n",
26
+ " 'To': 'leekwoon@unist.ac.kr'}"
27
+ ]
28
+ },
29
+ "execution_count": 5,
30
+ "metadata": {},
31
+ "output_type": "execute_result"
32
+ }
33
+ ],
34
+ "source": [
35
+ "import os\n",
36
+ "from postmarker.core import PostmarkClient\n",
37
+ "postmark = PostmarkClient(server_token=os.getenv(\"POSTMARK_API_KEY\"))\n",
38
+ "\n",
39
+ "subject = \"[kyobody - μžλ§‰μƒμ„±] μž‘μ—…μ΄ μ™„λ£Œλ˜μ—ˆμŠ΅λ‹ˆλ‹€.\"\n",
40
+ "body = \"[kyobody - μžλ§‰μƒμ„±] μž‘μ—…μ΄ μ™„λ£Œλ˜μ—ˆμŠ΅λ‹ˆλ‹€.SRT νŒŒμΌμ„ μ²¨λΆ€ν•˜μ—¬ μ „λ‹¬λ“œλ¦½λ‹ˆλ‹€.\"\n",
41
+ "\n",
42
+ "postmark.emails.send(\n",
43
+ " From='leekwoon@unist.ac.kr',\n",
44
+ " To='leekwoon@unist.ac.kr',\n",
45
+ " Subject=subject,\n",
46
+ " HtmlBody=body\n",
47
+ ")"
48
+ ]
49
+ },
50
+ {
51
+ "cell_type": "code",
52
+ "execution_count": null,
53
+ "metadata": {},
54
+ "outputs": [],
55
+ "source": [
56
+ "import os\n",
57
+ "from postmarker.core import PostmarkClient\n",
58
+ "\n",
59
+ "postmark = PostmarkClient(server_token=os.getenv(\"POSTMARK_API_KEY\"))\n",
60
+ "\n",
61
+ "subject = \"[kyobody - μžλ§‰μƒμ„±] μž‘μ—…μ΄ μ™„λ£Œλ˜μ—ˆμŠ΅λ‹ˆλ‹€.\"\n",
62
+ "body = \"[kyobody - μžλ§‰μƒμ„±] μž‘μ—…μ΄ μ™„λ£Œλ˜μ—ˆμŠ΅λ‹ˆλ‹€.SRT νŒŒμΌμ„ μ²¨λΆ€ν•˜μ—¬ μ „λ‹¬λ“œλ¦½λ‹ˆλ‹€.\"\n",
63
+ "\n",
64
+ "# Specify the file path\n",
65
+ "file_path = './README.md'\n",
66
+ "\n",
67
+ "# Send the email with the attachment\n",
68
+ "postmark.emails.send(\n",
69
+ " From='leekwoon@unist.ac.kr',\n",
70
+ " To='leekwoon@unist.ac.kr',\n",
71
+ " Subject=subject,\n",
72
+ " HtmlBody=body,\n",
73
+ " Attachments=[\n",
74
+ " {\n",
75
+ " \"Name\": os.path.basename(file_path),\n",
76
+ " \"Content\": open(file_path, \"rb\").read(),\n",
77
+ " \"ContentType\": \"application/octet-stream\"\n",
78
+ " }\n",
79
+ " ]\n",
80
+ ")"
81
+ ]
82
+ }
83
+ ],
84
+ "metadata": {
85
+ "kernelspec": {
86
+ "display_name": "kyobody",
87
+ "language": "python",
88
+ "name": "python3"
89
+ },
90
+ "language_info": {
91
+ "codemirror_mode": {
92
+ "name": "ipython",
93
+ "version": 3
94
+ },
95
+ "file_extension": ".py",
96
+ "mimetype": "text/x-python",
97
+ "name": "python",
98
+ "nbconvert_exporter": "python",
99
+ "pygments_lexer": "ipython3",
100
+ "version": "3.9.18"
101
+ }
102
+ },
103
+ "nbformat": 4,
104
+ "nbformat_minor": 2
105
+ }