-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsend_timesheet.py
More file actions
executable file
·40 lines (29 loc) · 946 Bytes
/
send_timesheet.py
File metadata and controls
executable file
·40 lines (29 loc) · 946 Bytes
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
31
32
33
34
35
36
37
38
39
40
# From http://docs.python.org/lib/node162.html
import smtplib
import mimetypes
from email import encoders
from email.message import Message
from email.mime.base import MIMEBase
from email.mime.multipart import MIMEMultipart
COMMASPACE = ', '
outer = MIMEMultipart()
outer['Subject'] = 'Timesheet'
outer['To'] = 'You <you@example.com>'
outer['From'] = 'Me <me@example.com>'
outer.preamble = 'You will not see this in a MIME-aware mail reader.\n'
ctype, encoding = mimetypes.guess_type(path)
if ctype is None or encoding is not None:
ctype = 'application/octet-stream'
maintype, subtype = ctype.split('/', 1)
fp = open(path, 'rb')
msg = MIMEBase(maintype, subtype)
msg.set_payload(fp.read())
fp.close()
encoders.encode_base64(msg)
msg.add_header('Content-Displosition', 'attachment', filename=filename)
outer.attach(msg)
composed = outer.as_string()
s = smtplib.SMTP()
s.connect()
s.sendmail(sender, recipients, composed)
sl.close()