summaryrefslogtreecommitdiffstats
path: root/Emailer.py
blob: 431ae9be04183244000b11c7689986ed5b150ee0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env python
# -*- coding: iso-8859-1 -*-

from smtplib import SMTP
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
from email.MIMEBase import MIMEBase
from email.Utils import formatdate
from email import Encoders
import os

def sendFile(to, attachment, message):
	sender = SMTP("smtp.gmail.com", 587)
	sender.ehlo()
	sender.starttls()
	sender.ehlo()
	sender.login("Jason@AnyClip.com", open(".emailpassword", "r").read())
	msg = MIMEMultipart()
	msg['From'] = "Jason A. Donenfeld <Jason@AnyClip.com>"
	msg['To'] = to
	msg['Date'] = formatdate(localtime=True)
	msg['Subject'] = "Your Movie Statistics Results"
	msg.attach(MIMEText(message))
	part = MIMEBase('application', "octet-stream")
	part.set_payload(open(attachment, "rb").read())
	Encoders.encode_base64(part)
	part.add_header('Content-Disposition', 'attachment; filename="%s"' % os.path.basename(attachment))
	msg.attach(part)
	sender.sendmail("Jason@AnyClip.com", to, msg.as_string())
	sender.close()