55 lines
1.4 KiB
Python
Executable file
55 lines
1.4 KiB
Python
Executable file
from email.mime.multipart import MIMEMultipart
|
|
from email.mime.text import MIMEText
|
|
from email.mime.base import MIMEBase
|
|
from email.mime.image import MIMEImage
|
|
from email import encoders
|
|
import smtplib
|
|
import os
|
|
import json
|
|
import subprocess
|
|
|
|
def take_screenshot():
|
|
filename = "./screenshot.png"
|
|
subprocess.call(["scrot", filename])
|
|
return filename
|
|
|
|
|
|
def send_email(login_file):
|
|
picture_name = take_screenshot()
|
|
|
|
json_data = open(login_file).read()
|
|
data = json.loads(json_data)
|
|
fromaddr = toaddr = data["email_address"]
|
|
password = data["password"]
|
|
|
|
msg = MIMEMultipart()
|
|
|
|
msg['From'] = fromaddr
|
|
msg['To'] = toaddr
|
|
msg['Subject'] = "Clock Status"
|
|
|
|
body = "Hello, world!"
|
|
|
|
msg.attach(MIMEText(body, 'plain'))
|
|
|
|
filename = "time.txt"
|
|
#attachment = open("./time.txt", "rb")
|
|
picture = open(picture_name, "rb")
|
|
|
|
#part = MIMEBase('application', 'octet-stream')
|
|
#part.set_payload((attachment).read())
|
|
#encoders.encode_base64(part)
|
|
#part.add_header('Content-Disposition', "attachment; filename= %s" % filename)
|
|
#msg.attach(part)
|
|
|
|
image = MIMEImage(picture.read(), name=os.path.basename(picture_name))
|
|
msg.attach(image)
|
|
|
|
server = smtplib.SMTP('smtp.gmail.com', 587)
|
|
server.starttls()
|
|
server.login(fromaddr, password)
|
|
text = msg.as_string()
|
|
server.sendmail(fromaddr, toaddr, text)
|
|
server.quit()
|
|
|
|
os.remove(picture_name)
|