-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsend_mail.py
executable file
·39 lines (29 loc) · 937 Bytes
/
send_mail.py
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
#! /usr/bin/python
import sys
import base64
import smtplib
args = sys.argv[1:]
if len(args) != 3:
print "Incorrect number of arguments (expected 3)"
print " Correct usage: " + sys.argv[0] + " subj body recip"
print " where subj, body, and recip are encoded in base64"
exit()
args = map(base64.b64decode,sys.argv[1:4])
(subj, body, recip) = (args[0],args[1],args[2])
# Import smtplib for the actual sending function
me = '"Your Past Self" <past.self@site.com>'
# Import the email modules we'll need
from email.mime.text import MIMEText
# Create a text/plain message
msg = MIMEText(body,'plain')
# me == the sender's email address
# you == the recipient's email address
msg['Subject'] = subj
msg['From'] = me
msg['To'] = recip
# Send the message via our own SMTP server, but don't include the
# envelope header.
s = smtplib.SMTP('localhost')
s.sendmail(me, [recip], msg.as_string())
s.quit()
print "Successfully sent mail"