-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmailthon.py
55 lines (41 loc) · 1.28 KB
/
mailthon.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
import os
import cherrypy
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from config import app_login, app_password
class Mailthon:
@cherrypy.expose
def index(self):
return open('html/index.html').read()
@cherrypy.expose
def send(self, mail, msg):
mm = MIMEMultipart()
mm.attach(MIMEText(msg, 'plan'))
server = smtplib.SMTP('smtp.gmail.com: 587')
server.starttls()
server.login(app_login, app_password)
server.sendmail(app_login, mail, mm.as_string())
server.quit()
return Mailthon.index(self)
if __name__ == '__main__':
if not os.path.exists('log'):
os.mkdir('log')
conf = {
'/': {
'tools.sessions.on': True,
'tools.staticdir.root': os.path.abspath(os.getcwd())
},
'/static': {
'tools.staticdir.on': True,
'tools.staticdir.dir': './public'
},
'global': {
'server.socket_host': '127.0.0.1',
'server.socket_port': 8080,
'engine.autoreload.on': False,
'log.access_file': './log/access.log',
'log.error_file': './log/error.log'
}
}
cherrypy.quickstart(Mailthon(), '/', conf)