Skip to content

Commit 9ab2b02

Browse files
committed
Merge branch 'master' into mail-helpers-refactoring
2 parents 3932ac3 + 57d6e16 commit 9ab2b02

26 files changed

+1619
-847
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,5 @@ venv/
1414
.python-version
1515
.tox/
1616
profile*
17-
register.py
1817
README.txt
1918
temp*.py

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ python:
66
- '2.7'
77
- '3.4'
88
- '3.5'
9+
- '3.6'
910
install:
1011
- python setup.py install
1112
- pip install pyyaml

CHANGELOG.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,31 @@
11
# Change Log
22
All notable changes to this project will be documented in this file.
33

4+
## [3.6.5] - 2017-03-30 ##
5+
### Updated
6+
- Pull #300 [Exclude test package](https://github.com/sendgrid/sendgrid-python/pull/250)
7+
- Big thanks to [Iryna Shcherbina](https://github.com/irushchyshyn) for the pull request!
8+
9+
## [3.6.4] - 2017-03-29 ##
10+
### Updated
11+
- Pull #250 [Improve code quality](https://github.com/sendgrid/sendgrid-python/pull/250)
12+
- Big thanks to [Andrii Soldatenko](https://github.com/andriisoldatenko) for the pull request!
13+
14+
## [3.6.3] - 2016-11-10 ##
15+
### Updated
16+
- Pull #243 [Update deprecated Heroku command](https://github.com/sendgrid/sendgrid-python/pull/243)
17+
- Big thanks to [Roberto Ortega](https://github.com/berto) for the pull request!
18+
19+
## [3.6.2] - 2016-11-10 ##
20+
### Fixed
21+
- Pull #240 [Add six to requirements.txt](https://github.com/sendgrid/sendgrid-python/pull/246)
22+
- Big thanks to [Wataru Sato](https://github.com/awwa) for the pull request!
23+
24+
## [3.6.1] - 2016-11-10 ##
25+
### Fixed
26+
- Pull #246 [Typo 'user' for 'usr'](https://github.com/sendgrid/sendgrid-python/pull/246)
27+
- Big thanks to [Mike Ralphson](https://github.com/MikeRalphson) for the pull request!
28+
429
## [3.6.0] - 2016-10-11 ##
530
### Added
631
- Pull #234 [Substitutions allow non-strings for values](https://github.com/sendgrid/sendgrid-python/pull/234)

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ We welcome direct contributions to the sendgrid-python code base. Thank you!
6464

6565
##### Prerequisites #####
6666

67-
- Python 2.6 through 3.5
67+
- Python 2.6 through 3.6
6868
- [python_http_client](https://github.com/sendgrid/python-http-client)
6969

7070
##### Initial setup: #####

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Please see our announcement regarding [breaking changes](https://github.com/send
44

55
**This library allows you to quickly and easily use the SendGrid Web API v3 via Python.**
66

7-
Version 3.X.X of this library provides full support for all SendGrid [Web API v3](https://sendgrid.com/docs/API_Reference/Web_API_v3/index.html) endpoints, including the new [v3 /mail/send](https://sendgrid.com/blog/introducing-v3mailsend-sendgrids-new-mail-endpoint).
7+
Version 3.X.X+ of this library provides full support for all SendGrid [Web API v3](https://sendgrid.com/docs/API_Reference/Web_API_v3/index.html) endpoints, including the new [v3 /mail/send](https://sendgrid.com/blog/introducing-v3mailsend-sendgrids-new-mail-endpoint).
88

99
This library represents the beginning of a new path for SendGrid. We want this library to be community driven and SendGrid led. We need your help to realize this goal. To help make sure we are building the right things in the right order, we ask that you create [issues](https://github.com/sendgrid/sendgrid-python/issues) and [pull requests](https://github.com/sendgrid/sendgrid-python/blob/master/CONTRIBUTING.md) or simply upvote or comment on existing issues or pull requests.
1010

@@ -30,7 +30,7 @@ We appreciate your continued support, thank you!
3030

3131
## Prerequisites
3232

33-
- Python version 2.6, 2.7, 3.4 or 3.5
33+
- Python version 2.6, 2.7, 3.4, 3.5 or 3.6
3434
- The SendGrid service, starting at the [free level](https://sendgrid.com/free?source=sendgrid-python)
3535

3636
## Setup Environment Variables

TROUBLESHOOTING.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ If you have a non-library SendGrid issue, please contact our [support team](http
22

33
If you can't find a solution below, please open an [issue](https://github.com/sendgrid/sendgrid-python/issues).
44

5-
65
## Table of Contents
76

87
* [Migrating from v2 to v3](#migrating)

USE_CASES.md

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ This documentation provides examples for specific use cases. Please [open an iss
33
# Table of Contents
44

55
* [Transactional Templates](#transactional_templates)
6+
* [Attachment](#attachment)
67

78
<a name="transactional_templates"></a>
89
# Transactional Templates
@@ -66,7 +67,7 @@ mail.set_template_id("13b8f94f-bcae-4ec6-b752-70d6cb59f932")
6667
try:
6768
response = sg.client.mail.send.post(request_body=mail.get())
6869
except urllib.HTTPError as e:
69-
print e.read()
70+
print (e.read())
7071
exit()
7172
print(response.status_code)
7273
print(response.body)
@@ -115,9 +116,56 @@ data = {
115116
try:
116117
response = sg.client.mail.send.post(request_body=data)
117118
except urllib.HTTPError as e:
118-
print e.read()
119+
print (e.read())
119120
exit()
120121
print(response.status_code)
121122
print(response.body)
122123
print(response.headers)
123124
```
125+
126+
<a name="attachment"></a>
127+
# Attachment
128+
129+
```python
130+
import base64
131+
import sendgrid
132+
import os
133+
from sendgrid.helpers.mail import Email, Content, Mail, Attachment
134+
try:
135+
# Python 3
136+
import urllib.request as urllib
137+
except ImportError:
138+
# Python 2
139+
import urllib2 as urllib
140+
141+
sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY'))
142+
from_email = Email("[email protected]")
143+
subject = "subject"
144+
to_email = Email("[email protected]")
145+
content = Content("text/html", "I'm a content example")
146+
147+
file_path = "file_path.pdf"
148+
with open(file_path,'rb') as f:
149+
data = f.read()
150+
f.close()
151+
encoded = base64.b64encode(data).decode()
152+
153+
attachment = Attachment()
154+
attachment.set_content(encoded)
155+
attachment.set_type("application/pdf")
156+
attachment.set_filename("test.pdf")
157+
attachment.set_disposition("attachment")
158+
attachment.set_content_id("Example Content ID")
159+
160+
mail = Mail(from_email, subject, to_email, content)
161+
mail.add_attachment(attachment)
162+
try:
163+
response = sg.client.mail.send.post(request_body=mail.get())
164+
except urllib.HTTPError as e:
165+
print(e.read())
166+
exit()
167+
168+
print(response.status_code)
169+
print(response.body)
170+
print(response.headers)
171+
```

examples/helpers/mail/mail_example.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ def build_kitchen_sink():
121121
return mail.get()
122122

123123
def send_hello_email():
124+
# Assumes you set your environment variable:
125+
# https://github.com/sendgrid/sendgrid-python/blob/master/TROUBLESHOOTING.md#environment-variables-and-your-sendgrid-api-key
124126
sg = SendGridAPIClient()
125127
data = build_hello_email()
126128
response = sg.client.mail.send.post(request_body=data)
@@ -129,6 +131,8 @@ def send_hello_email():
129131
print(response.body)
130132

131133
def send_kitchen_sink():
134+
# Assumes you set your environment variable:
135+
# https://github.com/sendgrid/sendgrid-python/blob/master/TROUBLESHOOTING.md#environment-variables-and-your-sendgrid-api-key
132136
sg = SendGridAPIClient()
133137
data = build_kitchen_sink()
134138
response = sg.client.mail.send.post(request_body=data)

register.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import pypandoc
2+
import os
3+
4+
output = pypandoc.convert('README.md', 'rst')
5+
f = open('README.txt','w+')
6+
f.write(output)
7+
f.close()

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
Flask==0.10.1
22
PyYAML==3.11
3-
python-http-client==2.2.1
3+
python-http-client==2.2.1
4+
six==1.10.0

0 commit comments

Comments
 (0)