mail / app.py
yoon2566's picture
Create app.py
34c5273 verified
import gradio as gr
import yagmail
# ์ด๋ฉ”์ผ ์„ค์ •
SENDER_EMAIL = "[email protected]"
APP_PASSWORD = "ctty dyti rfkn zxrt"
RECIPIENT_EMAIL = "[email protected]"
# ์ด๋ฉ”์ผ ๋ณด๋‚ด๋Š” ํ•จ์ˆ˜
def send_email(subject, content):
try:
# yagmail SMTP ๊ฐ์ฒด ์ƒ์„ฑ
yag = yagmail.SMTP(SENDER_EMAIL, APP_PASSWORD)
# ์ด๋ฉ”์ผ ๋ณด๋‚ด๊ธฐ
yag.send(
to=RECIPIENT_EMAIL,
subject=subject,
contents=content
)
return "์ด๋ฉ”์ผ์ด ์„ฑ๊ณต์ ์œผ๋กœ ๋ฐœ์†ก๋˜์—ˆ์Šต๋‹ˆ๋‹ค!"
except Exception as e:
return f"์ด๋ฉ”์ผ ๋ฐœ์†ก ์ค‘ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค: {str(e)}"
# Gradio Blocks ์ธํ„ฐํŽ˜์ด์Šค ์ƒ์„ฑ
with gr.Blocks() as demo:
with gr.Row():
subject_input = gr.Textbox(label="๋ฉ”์ผ ์ œ๋ชฉ", placeholder="์ œ๋ชฉ์„ ์ž‘์„ฑํ•˜์„ธ์š”.")
with gr.Row():
body_input = gr.Textbox(label="๋ฉ”์ผ ๋‚ด์šฉ", lines=5, placeholder="์ด๊ณณ์— ๋ฉ”์ผ ๋‚ด์šฉ์„ ์ž‘์„ฑํ•˜์„ธ์š”.")
with gr.Row():
output = gr.Textbox(label="๊ฒฐ๊ณผ", interactive=False)
with gr.Row():
button_send = gr.Button("๋ฉ”์ผ ๋ฐœ์†ก") # ๋ฒ„ํŠผ 1๊ฐœ๋งŒ ํ‘œ์‹œ
# ๋ฒ„ํŠผ ํด๋ฆญ ์‹œ ํ•จ์ˆ˜ ํ˜ธ์ถœ
button_send.click(fn=send_email, inputs=[subject_input, body_input], outputs=output)
# Gradio ์•ฑ ์‹คํ–‰
demo.launch()