From 66e18d23c91cd4d290b6cecfdc88680af2fb97e2 Mon Sep 17 00:00:00 2001 From: Wind Date: Sun, 15 Feb 2026 06:22:45 +0900 Subject: [PATCH] Fix Contact Form - Use mailcow network Postfix server successfully --- html/assets/js/script.js | 4 +++- html/status.json | 2 +- mail_contact.py | 24 ++++++++++++++++++------ 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/html/assets/js/script.js b/html/assets/js/script.js index 9eb4720..69d20cf 100644 --- a/html/assets/js/script.js +++ b/html/assets/js/script.js @@ -76,7 +76,9 @@ if (contactSubmitBtn) { try { // Python FastAPI 엔드포인트로 요청 - const response = await fetch('http://localhost:8001/api/contact', { + // 현재 페이지의 호스트를 사용 + const apiUrl = `${window.location.protocol}//${window.location.hostname}:8001/api/contact`; + const response = await fetch(apiUrl, { method: 'POST', headers: { 'Content-Type': 'application/json' diff --git a/html/status.json b/html/status.json index b9bae41..47048ee 100644 --- a/html/status.json +++ b/html/status.json @@ -1 +1 @@ -{"cpu_temp": "43", "nvme_temp": "35", "uptime_days": 2, "last_update": "06:16:01"} \ No newline at end of file +{"cpu_temp": "42", "nvme_temp": "35", "uptime_days": 2, "last_update": "06:22:01"} \ No newline at end of file diff --git a/mail_contact.py b/mail_contact.py index 549439a..5dd119d 100644 --- a/mail_contact.py +++ b/mail_contact.py @@ -48,15 +48,19 @@ class ContactForm(BaseModel): async def send_contact_email(form: ContactForm): """Contact form email handler""" try: - # SMTP 설정 - smtp_server = "mailcowdockerized_postfix-mailcow_1" # Docker 네트워크 내 호스트명 - smtp_port = 25 # 일반 포트 (요청할 때) + # SMTP 설정 - mailcow Postfix 서버 + # Docker 네트워크 내에서는 서비스 이름으로 접근 + smtp_server = "mailcowdockerized_postfix-mailcow_1" + smtp_port = 25 + + print(f"Attempting to connect to SMTP: {smtp_server}:{smtp_port}") # 메시지 구성 msg = MIMEMultipart('alternative') msg['Subject'] = f"[Contact Form] {form.name} - {form.company}" - msg['From'] = form.email + msg['From'] = "contact@hanmocnn.co.kr" msg['To'] = "windpacer@hanmocnn.co.kr" + msg['Reply-To'] = form.email # 텍스트 본문 text_body = f""" @@ -69,7 +73,7 @@ Message: {form.message} --- -Submitted from Contact Form +Submitted from Hanmo Contact Form """ # HTML 본문 @@ -94,12 +98,20 @@ Submitted from Contact Form msg.attach(part2) # SMTP 연결 및 메일 전송 + print(f"Connecting to SMTP server...") with smtplib.SMTP(smtp_server, smtp_port, timeout=10) as server: + print(f"Connected! Sending email...") server.sendmail( - form.email, + "contact@hanmocnn.co.kr", "windpacer@hanmocnn.co.kr", msg.as_string() ) + print(f"Email sent successfully!") + + return { + "success": True, + "message": "Your message has been sent successfully. We will get back to you soon." + } return { "success": True,