Skip to content

Commit 3d29cf7

Browse files
author
elbuo8
committed
Updated dependencies, fixed file upload and pypi setup
1 parent b3d2f1d commit 3d29cf7

7 files changed

Lines changed: 36 additions & 71 deletions

File tree

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
1+
build
2+
dist
3+
sdist
4+
*.egg
5+
*.egg-info
16
*.pyc
27
venv/

sendgrid/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from sendgrid import SendGridClient
2+
from message import Mail

sendgrid/header.py

Lines changed: 0 additions & 60 deletions
This file was deleted.

sendgrid/message.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import io
12
import rfc822
23
import base64
3-
from header import SMTPAPIHeader
4+
from smtpapi import SMTPAPIHeader
45

56

67
class Mail(SMTPAPIHeader):
@@ -102,7 +103,13 @@ def add_attachment(self, name, filepath):
102103
file: path to file or data string
103104
104105
"""
105-
self.files[name] = base64.urlsafe_b64encode(open(filepath, "rb").read())
106+
self.files[name] = open(filepath, "rb").read()
107+
108+
def add_attachment_stream(self, name, string):
109+
if isinstance(string, str):
110+
self.files[name] = string
111+
elif isinstance(string, io.BytesIO):
112+
self.files[name] = string.read()
106113

107114
def set_headers(self, headers):
108115
self.headers = headers

sendgrid/sendgrid.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import requests
2-
import urllib
32

43
class SendGridClient(object):
54
"""
65
SendGrid API
76
"""
8-
def __init__(self, username, password):
7+
def __init__(self, username, password, **opts):
98
"""
109
Construct Sendgrid API object
1110
@@ -17,6 +16,7 @@ def __init__(self, username, password):
1716
self.username = username
1817
self.password = password
1918
self.mailUrl = 'https://api.sendgrid.com/api/mail.send.json'
19+
self.proxies = opts.get('proxies', None)
2020

2121
def send(self, message):
2222
values = {}
@@ -34,8 +34,5 @@ def send(self, message):
3434
for filename in message.files:
3535
values['files[' + filename + ']'] = message.files[filename]
3636
values['x-smtpapi'] = str(message.api_header_as_json())
37-
print values
38-
r = requests.get(self.mailUrl,params=values)
39-
print
40-
print r.url
41-
return r.text
37+
r = requests.get(self.mailUrl, params=values, proxies=self.proxies)
38+
return r.status_code, r.json()

setup.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@
22

33
setup(
44
name='sendgrid',
5-
version='0.1.4',
5+
version='0.2.0',
66
author='Yamil Asusta',
77
author_email='yamil@sendgrid.com',
8-
packages=find_packages(),
98
url='https://github.com/sendgrid/sendgrid-python/',
9+
packages=find_packages(),
1010
license='LICENSE.txt',
1111
description='SendGrid library for Python',
1212
long_description='SendGrid library for Python',
13+
install_requires=[
14+
'requests',
15+
'smtpapi'
16+
],
1317
)

test/main_test.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import os
2+
from sendgrid import SendGridClient, Mail
3+
4+
sg = SendGridClient(os.getenv('SG_USER'), os.getenv('SG_PWD'))
5+
m = Mail(to=['yamil.asusta@upr.edu'])
6+
m.set_from('yamil@sendgrid.com')
7+
m.set_subject('JAJA')
8+
m.set_text('fail')
9+
m.add_attachment_stream('test.txt', 'Testing them string bro')
10+
print str(sg.send(m))

0 commit comments

Comments
 (0)