From 190d439a9337e2381024b0c45f11cfff17c270ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=A2=85=ED=98=84?= <ljh0819@ajou.ac.kr> Date: Thu, 21 Dec 2023 18:02:16 +0900 Subject: [PATCH] Update send_email.py --- send_email.py | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/send_email.py b/send_email.py index c28e280..52da89a 100644 --- a/send_email.py +++ b/send_email.py @@ -1,34 +1,25 @@ -import os import smtplib from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText from email.mime.image import MIMEImage -sender_email = "your_email@gmail.com" -sender_password = "your_password" +sender_email = "0819ljh@naver.com" +sender_password = "" //비밀번호는 생략하였습니다. -recipient_email = "recipient_email@example.com" +recipient_email = "day305@naver.com" -smtp_server = "smtp.gmail.com" +smtp_server = "smtp.naver.com" smtp_port = 587 -image_dir = "path/to/your/image/directory" - -image_files = [f for f in os.listdir(image_dir) if f.lower().endswith(('.png', '.jpg', '.jpeg'))] - -latest_image = max(image_files, key=lambda x: os.path.getmtime(os.path.join(image_dir, x))) - -image_path = os.path.join(image_dir, latest_image) - msg = MIMEMultipart() msg['From'] = sender_email msg['To'] = recipient_email -msg['Subject'] = "이메일 제목" +msg['Subject'] = "OO지역에 흡연 감지됨됨" -body = "이메일 본문 내용" +body = "OO지역에 흡연이 감지되었습니다. 지속적인흡연이감지되면 관리자는 확인부탁드리겠습니다." msg.attach(MIMEText(body, 'plain')) -with open(image_path, "rb") as image_file: +with open("/home/pi/cat.jpg", "rb") as image_file: image = MIMEImage(image_file.read()) msg.attach(image) @@ -36,5 +27,3 @@ with smtplib.SMTP(smtp_server, smtp_port) as server: server.starttls() server.login(sender_email, sender_password) server.sendmail(sender_email, recipient_email, msg.as_string()) - -print(f"최근 이미지 '{latest_image}'를 이메일로 전송했습니다.") -- GitLab