Skip to content
Snippets Groups Projects
Commit 59a30f09 authored by 이종현's avatar 이종현
Browse files

Add new file

parent 09f97daf
No related branches found
No related tags found
No related merge requests found
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"
recipient_email = "recipient_email@example.com"
smtp_server = "smtp.gmail.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'] = "이메일 제목"
body = "이메일 본문 내용"
msg.attach(MIMEText(body, 'plain'))
with open(image_path, "rb") as image_file:
image = MIMEImage(image_file.read())
msg.attach(image)
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}'를 이메일로 전송했습니다.")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment