import smtplib
from email.message import EmailMessage
msg = EmailMessage()
msg.set_content("이것은 파이썬으로 보낸 간단한 메일입니다.")
msg["Subject"] = "간단한 메일"
msg["From"] = "your_email@gmail.com"
msg["To"] = "receiver@example.com"
# Gmail SMTP 서버 사용
smtp_server = "smtp.gmail.com"
smtp_port = 587
# Gmail은 앱 비밀번호 사용해야 함!
email = "your_email@gmail.com"
password = "your_app_password"
with smtplib.SMTP(smtp_server, smtp_port) as server:
server.starttls()
server.login(email, password)
server.send_message(msg)
print("메일 전송 완료!")
-----스크린샷찍어서 보내기----------
import smtplib
from email.message import EmailMessage
import pyautogui # 스크린샷 찍기
import os
# 1. 스크린샷 찍고 저장
screenshot_path = "screenshot.png"
screenshot = pyautogui.screenshot()
screenshot.save(screenshot_path)
# 2. 이메일 구성
msg = EmailMessage()
msg["Subject"] = "스크린샷 전송"
msg["From"] = "your_email@gmail.com"
msg["To"] = "receiver@example.com"
msg.set_content("첨부된 스크린샷을 확인해주세요.")
# 3. 첨부파일 추가 (스크린샷)
with open(screenshot_path, "rb") as f:
img_data = f.read()
msg.add_attachment(img_data, maintype="image", subtype="png", filename="screenshot.png")
# 4. SMTP를 이용해 메일 전송 (Gmail 기준)
smtp_server = "smtp.gmail.com"
smtp_port = 587
email = "your_email@gmail.com"
password = "your_app_password" # 앱 비밀번호
with smtplib.SMTP(smtp_server, smtp_port) as server:
server.starttls()
server.login(email, password)
server.send_message(msg)
print("메일 전송 완료!")
# 5. (선택) 스크린샷 파일 삭제
os.remove(screenshot_path)
-----스크린샷찍어서 보내기----------
구글 계정 들어가서 보안 들어가서 앱 비밀번호 발급해서 "your_app_password"에 넣어서 사용