Created
April 5, 2013 18:14
-
-
Save puentesarrin/5321409 to your computer and use it in GitHub Desktop.
TornadoMail demo using a tornado.template.Loader.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>TornadoMail Demo</title> | |
</head> | |
<body> | |
<form method="post" action="/"> | |
<input type="text" name="subject"/> | |
<input type="text" name="email"/> | |
<input type="submit" value="Send message"/> | |
</form> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h1>Hello {{ name }}!<h1> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 *-* | |
from tornado import ioloop, template, web | |
from tornadomail.message import EmailFromTemplate | |
from tornadomail.backends.smtp import EmailBackend | |
class Application(web.Application): | |
@property | |
def mail_connection(self): | |
return EmailBackend( | |
'smtp.gmail.com', 587, '<your google mail>', | |
'<your google password>', True, | |
template_loader=template.Loader('.') | |
) | |
class MainHandler(web.RequestHandler): | |
@property | |
def mail_connection(self): | |
return self.application.mail_connection | |
def get(self): | |
self.render("index.html") | |
def post(self): | |
message = EmailFromTemplate( | |
self.get_argument('subject'), | |
'mailtemplate.html', | |
params={'name': 'Jorge'}, | |
from_email='<your google mail>', | |
to=[self.get_argument('email')], | |
connection=self.mail_connection | |
) | |
message.send() | |
self.render("index.html") | |
if __name__ == '__main__': | |
application = Application([ | |
(r'/', MainHandler), | |
], | |
template_path='.' | |
) | |
application.listen(8888) | |
ioloop.IOLoop.instance().start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks. This helps me a lot.