-
Notifications
You must be signed in to change notification settings - Fork 38
/
testproject.py
executable file
·65 lines (48 loc) · 1.56 KB
/
testproject.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
#!/usr/bin/env python
import logging
import tornado.httpserver
import tornado.ioloop
import tornado.options
import tornado.web
from tornado import gen
from tornado.options import define, options
from tornadomail.message import EmailMessage
from tornadomail.backends.smtp import EmailBackend
define("port", default=8888, help="run on the given port", type=int)
logging.basicConfig(level=logging.DEBUG)
class Application(tornado.web.Application):
@property
def mail_connection(self):
return EmailBackend(
'smtp.gmail.com', 587, '<your google email>', '<your google password>',
True
)
class MainHandler(tornado.web.RequestHandler):
@property
def mail_connection(self):
return self.application.mail_connection
def get(self):
self.render("index.html")
def post(self):
def _finish(num):
print 'sended %d message(s)' % num
self.render("index.html")
message = EmailMessage(
self.get_argument('subject'),
self.get_argument('message'),
'<your google email>',
[self.get_argument('email')],
connection=self.mail_connection
)
message.send()#callback=_finish)
self.render("index.html")
def main():
tornado.options.parse_command_line()
application = Application([
(r"/", MainHandler),
])
http_server = tornado.httpserver.HTTPServer(application)
http_server.listen(options.port)
tornado.ioloop.IOLoop.instance().start()
if __name__ == "__main__":
main()