diff --git a/send_email.py b/send_email.py index c28e280c6f3375f255b8b055e76a5b4bff3eff84..52da89a0fda16043cea049f2fbb1018b3d8707cb 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}'를 이메일로 전송했습니다.")