-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmail_wrapper.py
82 lines (71 loc) · 2.12 KB
/
mail_wrapper.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env python
import smtplib
from email.Header import Header
from email.mime.text import MIMEText
from email.mime.image import MIMEImage
from email.mime.multipart import MIMEMultipart
import farmer_log
import sys
mail_from = "[email protected]"
mail_to = "[email protected]"
def sendMail(sender, receiver, subject):
smtpserver = "smtp.intel.com"
msg = MIMEMultipart("related")
msg["Subject"] = Header(subject, "utf-8")
html = """
<html>
<head>This is a test</head>
<body>
<br><img width=75 height=134 alt="" src="cid:meinv_image"/></br>
</body>
</html>
"""
htm = MIMEText(html, 'html', 'utf-8')
msg.attach(htm)
fp = open('12.PNG', 'rb')
msgImage = MIMEImage(fp.read())
fp.close()
msgImage.add_header("Content-ID", "<meinv_image>")
msg.attach(msgImage)
att = MIMEText(open("log.tar.gz").read(), "base64", "utf-8")
att["Content-Type"] = "application/octet-stream"
att["Content-Disposition"] = 'attachment;filename="log.tar.gz"'
msg.attach(att)
smtp = smtplib.SMTP()
try:
smtp.connect(smtpserver)
smtp.sendmail(sender, receiver, msg.as_string())
except Exception as e:
print e
finally:
smtp.quit()
def send_security_code(sender, receiver, securityCode):
result = True
smtpserver = "smtp.intel.com"
msg = MIMEMultipart("alternative")
msg["Subject"] = Header("Security Code[%s]" % securityCode, "utf-8")
html = """
<html>
<head>Security Code:</head>
<body>
<p><label><h4>%s</h4></label></p>
</body>
</html>
""" % securityCode
htm = MIMEText(html, 'html', 'utf-8')
msg.attach(htm)
smtp = smtplib.SMTP()
try:
smtp.connect(smtpserver)
smtp.sendmail(sender, receiver, msg.as_string())
except Exception as e:
result = False
farmer_log.error("%s" % e)
finally:
smtp.quit()
return result
if __name__ == "__main__":
mail_from = sys.argv[1]
mail_to = sys.argv[2]
secCode = sys.argv[3]
send_security_code(mail_from, mail_to, secCode)