Skip to content

Commit 4abbb68

Browse files
committed
Merge pull request themartorana#56 from tigrus/master
postmark mixin for tornado
2 parents eed9434 + 435c71a commit 4abbb68

2 files changed

Lines changed: 42 additions & 0 deletions

File tree

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,28 @@ EMAIL_BACKEND = 'postmark.django_backend.EmailBackend'
6666

6767
But keep in mind that even when using standard Django functions the sender must be registered with postmarkapp.com.
6868

69+
Tornado
70+
-------
71+
72+
For tornado support of postmark implemented as Mixin.
73+
74+
Example of usage:
6975

76+
```python
77+
import tornado.web
78+
import tornado.options
79+
from postmark.tornado_mixin import PostmarkMixin
80+
81+
tornado.options.define('postmark_signature', 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx')
82+
tornado.options.define('postmark_sendemail', '[email protected]')
83+
84+
class EmailHandler(tornado.web.RequestHandler, PostmarkMixin):
85+
def post(self):
86+
87+
body = 'This is test message'
88+
subject = 'Test Message'
89+
self.send_email(body=body, to=to, subject=subject)
90+
```
7091
Exceptions
7192
-----------
7293

postmark/tornado_mixin.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""
2+
Postmark Mixin
3+
"""
4+
from tornado.options import options as opt
5+
import postmark
6+
7+
class PostmarkMixin(object):
8+
def send_email(self, **kwargs):
9+
subject=kwargs.get('subject')
10+
body=kwargs.get('body')
11+
to=kwargs.get('to')
12+
postsig = opt.postmark_signature
13+
postemail = opt.postmark_sendemail
14+
15+
sender = postmark.PMMail()
16+
sender.sender = postemail
17+
sender.api_key = postsig
18+
sender.to = to
19+
sender.html_body = body
20+
sender.subject = subject
21+
sender.send(test=False)

0 commit comments

Comments
 (0)