From e34568416299e359301c049d709b05b055c07fb8 Mon Sep 17 00:00:00 2001 From: jaehwang Date: Thu, 27 Nov 2025 11:19:16 +0900 Subject: [PATCH] =?UTF-8?q?=EB=8F=99=EC=9D=BC=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=ED=8C=8C=EC=9D=B4=EC=8D=AC=20=ED=8C=8C=EC=9D=BC=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- smtp.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 smtp.py diff --git a/smtp.py b/smtp.py new file mode 100644 index 0000000..d110aff --- /dev/null +++ b/smtp.py @@ -0,0 +1,38 @@ +import smtplib +from email import encoders +from email.mime.base import MIMEBase +from email.mime.multipart import MIMEMultipart +from email.mime.text import MIMEText +from email.encoders import encode_base64 +import os +from dotenv import load_dotenv + +load_dotenv() + +SMTP_SERVER = os.getenv("SMTP_SERVER") # 네이버 smtp, 보내는 서버 기준 smtp 도메인 확인 +SMTP_USER_ID = os.getenv("SMTP_USER_ID") # 송신자 ID / 현재는 SMTP 서버 로그인 + 송신자 +SMTP_USER_PW = os.getenv("SMTP_USER_PW") # 송신자 PW / 네이버의 경우 SMTP전용 PW 발급 +SMTP_PORT = os.getenv("SMTP_PORT")# SMTP PORT, 기본 587 + +TARGET_FILE_PATH = "c:/o2o/smtp-mail-send-test/data/테스트피디엪.pdf" # 파일 경로 +file_name = "테스트 pdf.pdf" # 첨부파일명 +part = MIMEBase('application', "octet-stream") +part.set_payload(open(TARGET_FILE_PATH,"rb").read()) +encode_base64(part) +part.add_header('Content-Disposition', 'attachment', filename=file_name) + +reciever = "jhyeu@o2o.kr" # 수신자 +with smtplib.SMTP(SMTP_SERVER, SMTP_PORT) as smtp: + smtp.starttls() + smtp.login(SMTP_USER_ID, SMTP_USER_PW) + content = "This is an automated message being sent by Python. Python is the mastermind behind this." + msg = MIMEMultipart() + msg['From'] = SMTP_USER_ID + msg['Subject'] = '메일 발송 시험' + msg['To'] = reciever + + body = MIMEText(content, _charset='utf-8') + msg.attach(body) + msg.attach(part) + smtp.sendmail(SMTP_USER_ID, reciever, msg.as_string()) + \ No newline at end of file