import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email import encoders

import datetime
now = datetime.datetime.now()

fromaddr = "email@gmail.com"
toaddr = "email@gmail.com"

msg = MIMEMultipart()

msg['From'] = fromaddr
msg['To'] = toaddr
msg['Subject'] = "CatFeeder:" + " %s" % now.strftime("%m/%d/%Y %H:%M")

body = "Image Taken:" + " %s" % now.strftime("%m/%d/%Y %H:%M")

msg.attach(MIMEText(body, 'plain'))

filename = "attachment.jpg"
attachment = open("/var/www/html/images/CatFeeder_Latest.jpg", "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)

server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login(fromaddr, "xioeyrpywqnnvvkv")
text = msg.as_string()
server.sendmail(fromaddr, toaddr, text)
server.quit()