-
Notifications
You must be signed in to change notification settings - Fork 38
/
test.py
47 lines (37 loc) · 1.19 KB
/
test.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
# import contextlib
from tornado import ioloop
from tornadomail import send_mail
from tornadomail.backends.smtp import EmailBackend
from tornado import stack_context
def callback(*args, **kwargs):
callback.count = callback.count + 1
if callback.count == 5:
print 'about to stop ioloop'
ioloop.IOLoop.instance().stop()
else:
print 'callback count : ', callback.count
print 'Successfully sent'
print '*************'
callback.count = 0
def error_handler(e, msg, traceback):
print 'Error:'
print msg
print '**************'
ioloop.IOLoop.instance().stop()
return True
l = ['[email protected]', '[email protected]',
with stack_context.ExceptionStackContext(error_handler):
for to in l:
print 'to : ', to
print 'sending mail'
send_mail(
'Uber Now', 'Time to book uber', '[email protected]',
[to], callback=callback,
connection=EmailBackend(
'smtp.gmail.com', 587, 'username', 'userpassoword,
True
)
)
print 'mail initiated\n*************\n'
ioloop.IOLoop.instance().start()