forked from sendgrid/sendgrid-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsendgrid.py
More file actions
50 lines (43 loc) · 1.17 KB
/
sendgrid.py
File metadata and controls
50 lines (43 loc) · 1.17 KB
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
def memoize(f):
"""
Memoization decorator
"""
cache= {}
def func(*args):
if args not in cache:
cache[args] = f(*args)
return cache[args]
return func
class Sendgrid(object):
"""
Sendgrid API
"""
def __init__(self, username, password, **opts):
"""
Construct Sendgrid API object
Args:
username: Sendgrid username
password: Sendgrid password
secure: Use SSL/TLS
user: Send mail on behalf of this user (web only)
"""
self.username = username
self.password = password
self.secure = opts.get('secure', True)
self.user = opts.get('user', None)
@property
@memoize
def web(self):
"""
Return web transport
"""
from transport import web
return web.Http(self.username, self.password, ssl=self.secure, user=self.user)
@property
@memoize
def smtp(self):
"""
Return smtp transport
"""
from transport import smtp
return smtp.Smtp(self.username, self.password, tls=self.secure)