Skip to content

Commit b83cd62

Browse files
committed
[add] #610 Q&A 답변 메일 템플릿 적용
1 parent 9e129cc commit b83cd62

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

lib/mail.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,6 @@ async def send_qa_mail(request: Request, qa: QaContent) -> None:
214214
Args:
215215
request (Request): Request 객체
216216
poll_etc (PollEtc): 기타의견 객체
217-
218-
TODO : 메일 발송 템플릿 적용이 필요하다.
219217
"""
220218
with DBConnect().sessionLocal() as db:
221219
request.state.config = config = db.query(Config).first()
@@ -225,11 +223,22 @@ async def send_qa_mail(request: Request, qa: QaContent) -> None:
225223
from_name = get_admin_email_name(request)
226224
subject = f"[{config.cf_title}] {qa_config.qa_title} 질문 알림 메일"
227225
content = qa.qa_subject + "<br><br>" + qa.qa_content
226+
templates = Jinja2Templates(
227+
directory=TemplateService.get_templates_dir())
228228

229229
if qa.qa_parent:
230230
question = db.get(QaContent, qa.qa_parent)
231231
if question.qa_email_recv and question.qa_email:
232232
subject = f"{subject} 에 대한 답변이 등록되었습니다."
233+
content = templates.TemplateResponse(
234+
"bbs/mail_form/qa_answered_mail.html", {
235+
"request": request,
236+
"qa_subject": qa.qa_subject,
237+
"qa_name": qa.qa_name,
238+
"qa_content": qa.qa_content,
239+
"link_url": request.url_for("qa_view", qa_id=qa.qa_parent),
240+
}
241+
).body.decode("utf-8")
233242
mailer(from_email, question.qa_email, subject, content, from_name)
234243
else:
235244
if qa_config.qa_admin_email:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<!doctype html>
2+
<html lang="ko">
3+
<head>
4+
<meta charset="utf-8">
5+
<title>{{ qa_subject }} 알림 메일</title>
6+
</head>
7+
<body>
8+
<div style="margin:30px auto;width:600px;border:10px solid #f7f7f7">
9+
<div style="border:1px solid #dedede">
10+
{% if qa_subject %}
11+
<h1 style="padding:30px 30px 0;background:#f7f7f7;color:#555;font-size:1.4em">
12+
{{ qa_subject }}
13+
</h1>
14+
{% endif %}
15+
<span style="display:block;padding:10px 30px 30px;background:#f7f7f7;text-align:right">
16+
작성자 : {{ qa_name }}
17+
</span>
18+
<div style="margin:20px 0 0;padding:30px 30px 50px;min-height:200px;height:auto !important;height:200px;border-bottom:1px solid #eee">
19+
{{ qa_content }}
20+
</div>
21+
<a href="{{ link_url }}" style="display:block;padding:30px 0;background:#484848;color:#fff;text-decoration:none;text-align:center">사이트에서 확인하기</a>
22+
</div>
23+
</div>
24+
</body>
25+
</html>

0 commit comments

Comments
 (0)