Skip to content

Commit 4d9b68d

Browse files
committed
Merge remote-tracking branch 'upstream/master' into pydoc-update
Shuffle docs around to fit the new Mail helper structure. Hopefully I didn't miss anything; due to the amount of code getting moved around. I'll check the diff against master and then revert if needed.
2 parents a1466e1 + 35cc980 commit 4d9b68d

37 files changed

Lines changed: 1963 additions & 1751 deletions

.codeclimate.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
engines:
2+
pep8:
3+
enabled: true
4+
ratings:
5+
paths:
6+
- "**.py"

.env_sample

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export SENDGRID_API_KEY=''

.github/PULL_REQUEST_TEMPLATE

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<!--
2+
We appreciate the effort for this pull request but before that please make sure you read the contribution guidelines given above, then fill out the blanks below.
3+
4+
5+
Please enter each Issue number you are resolving in your PR after one of the following words [Fixes, Closes, Resolves]. This will auto-link these issues and close them when this PR is merged!
6+
e.g.
7+
Fixes #1
8+
Closes #2
9+
-->
10+
# Fixes #
11+
12+
### Checklist
13+
- [ ] I have made a material change to the repo (functionality, testing, spelling, grammar)
14+
- [ ] I have read the [Contribution Guide] and my PR follows them.
15+
- [ ] I updated my branch with the master branch.
16+
- [ ] I have added tests that prove my fix is effective or that my feature works
17+
- [ ] I have added necessary documentation about the functionality in the appropriate .md file
18+
- [ ] I have added in line documentation to the code I modified
19+
20+
### Short description of what this PR does:
21+
-
22+
-
23+
24+
If you have questions, please send an email to [Sendgrid](mailto:dx@sendgrid.com), or file a Github Issue in this repository.

PULL-REQUEST-TEMPLATE.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!--
2+
(We appreciate the effort for this pull request but before that please make sure you read the contribution guidelines given above, then fill out the blanks below.)
3+
-->
4+
5+
# Fixes #<!--Enter Issue number you have referenced(please refer only one issue at once)-->
6+
7+
### Checklist
8+
<!-- Do Star this repository and follow this template for your PR to be considered-->
9+
- [ ] I have read the SendGrid Contributor License Agreement (CLA)
10+
- [ ] I have read the [Contribution Guide] and my PR follows them.
11+
- [ ] My branch is up-to-date with the master branch.
12+
- [ ] I have added tests that prove my fix is effective or that my feature works
13+
- [ ] I have added necessary documentation (if appropriate)
14+
<!-- If an existing function does not have a docstring, please add one -->
15+
- [ ] All the functions created/modified in this PR contain relevant docstrings.
16+
17+
### Short description of what this resolves:
18+
19+
### Changes proposed in this pull request:
20+
<!--Fill These Bullet Points-->
21+
22+
23+
If you have questions, please send an email to [Sendgrid](mailto:dx@sendgrid.com), or file a Github Issue in this repository.

PULL_REQUEST_TEMPLATE

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<!--
2+
(Thanks for sending a pull request! Please make sure you click the link above to view the contribution guidelines, then fill out the blanks below.)
3+
-->
4+
<!-- Add the issue number that is fixed by this PR (In the form Fixes #123) -->
5+
6+
Fixes #<!--Enter Issue number you have referenced(please refer only one issue at once)-->
7+
8+
#### Checklist
9+
<!-- Please Star this repository and follow this template for your PR to be considered-->
10+
- [ ] I have read the SendGrid Contributor License Agreement (CLA)
11+
- [ ] I have read the [Contribution Guide] and my PR follows them.
12+
- [ ] My branch is up-to-date with the master branch.
13+
- [ ] I have added tests that prove my fix is effective or that my feature works
14+
- [ ] I have added necessary documentation (if appropriate)
15+
<!-- If an existing function does not have a docstring, please add one -->
16+
- [ ] All the functions created/modified in this PR contain relevant docstrings.
17+
18+
#### Short description of what this resolves:
19+
20+
21+
#### Changes proposed in this pull request:
22+
<!--Fill These Bullet Points-->
23+
24+
25+
If you have questions, please send an email [Sendgrid](mailto:dx@sendgrid.com), or file a Github Issue in this repository.
26+

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ echo "sendgrid.env" >> .gitignore
5555
source ./sendgrid.env
5656
```
5757

58+
Sengrid also supports local enviroment file `.env`. Copy or rename `.env_sample` into `.env` and update [SENGRID_API_KEY](https://app.sendgrid.com/settings/api_keys) with your key.
59+
5860
## Install Package
5961

6062
```bash

USAGE.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ print response.headers
389389
```
390390
## Retrieve an existing API Key
391391

392-
**This endpoint allows you to retrieve a single api key.**
392+
**This endpoint allows you to retrieve a single API key.**
393393

394394
If the API Key ID does not exist an HTTP 404 will be returned.
395395

@@ -3020,7 +3020,7 @@ print response.headers
30203020
```
30213021
## Delete a subuser
30223022

3023-
This endpoint allows you to delete a subuser. This is a permanent action, once deleted a subuser cannot be retrieved.
3023+
This endpoint allows you to delete a subuser. This is a permanent action, once you delete a subuser it cannot be retrieved.
30243024

30253025
For more information about Subusers:
30263026

@@ -3308,7 +3308,7 @@ print response.headers
33083308

33093309
**This endpoint allows you to remove an email address from your bounce list.**
33103310

3311-
Bounces are messages that are returned to the server that sent it. This endpoint allows you to delete a single email addresses from your bounce list.
3311+
Bounces are messages that are returned to the server that sent it. This endpoint allows you to delete a single email address from your bounce list.
33123312

33133313
For more information see:
33143314

docker/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ WORKDIR /root
1818

1919
# install Prism
2020
ADD https://raw.githubusercontent.com/stoplightio/prism/master/install.sh install.sh
21-
RUN chmod +x ./install.sh && \
21+
RUN chmod +x ./install.sh && sync && \
2222
./install.sh && \
2323
rm ./install.sh
2424

examples/helpers/mail/mail_example.py

Lines changed: 146 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
from sendgrid.helpers.mail import *
55
from sendgrid import *
66

7-
# NOTE: you will need move this file to the root directory of this project to execute properly.
7+
# NOTE: you will need move this file to the root
8+
# directory of this project to execute properly.
9+
810

911
def build_hello_email():
1012
"""Minimum required to send an email"""
@@ -17,66 +19,148 @@ def build_hello_email():
1719

1820
return mail.get()
1921

20-
def build_kitchen_sink():
21-
"""All settings set"""
22-
mail = Mail()
2322

24-
mail.from_email = Email("test@example.com", "Example User")
23+
def build_personalization(personalization):
24+
"""Build personalization mock instance from a mock dict"""
25+
mock_personalization = Personalization()
26+
for to_addr in personalization['to_list']:
27+
personalization.add_to(to_addr)
2528

26-
mail.subject = "Hello World from the SendGrid Python Library"
29+
for cc_addr in personalization['cc_list']:
30+
personalization.add_to(cc_addr)
2731

28-
personalization = Personalization()
29-
personalization.add_to(Email("test1@example.com", "Example User"))
30-
personalization.add_to(Email("test2@example.com", "Example User"))
31-
personalization.add_cc(Email("test3@example.com", "Example User"))
32-
personalization.add_cc(Email("test4@example.com", "Example User"))
33-
personalization.add_bcc(Email("test5@example.com"))
34-
personalization.add_bcc(Email("test6@example.com"))
35-
personalization.subject = "Hello World from the Personalized SendGrid Python Library"
36-
personalization.add_header(Header("X-Test", "test"))
37-
personalization.add_header(Header("X-Mock", "true"))
38-
personalization.add_substitution(Substitution("%name%", "Example User"))
39-
personalization.add_substitution(Substitution("%city%", "Denver"))
40-
personalization.add_custom_arg(CustomArg("user_id", "343"))
41-
personalization.add_custom_arg(CustomArg("type", "marketing"))
42-
personalization.send_at = 1443636843
43-
mail.add_personalization(personalization)
44-
45-
personalization2 = Personalization()
46-
personalization2.add_to(Email("test1@example.com", "Example User"))
47-
personalization2.add_to(Email("test2@example.com", "Example User"))
48-
personalization2.add_cc(Email("test3@example.com", "Example User"))
49-
personalization2.add_cc(Email("test4@example.com", "Eric Shallock"))
50-
personalization2.add_bcc(Email("test5@example.com"))
51-
personalization2.add_bcc(Email("test6@example.com"))
52-
personalization2.subject = "Hello World from the Personalized SendGrid Python Library"
53-
personalization2.add_header(Header("X-Test", "test"))
54-
personalization2.add_header(Header("X-Mock", "true"))
55-
personalization2.add_substitution(Substitution("%name%", "Example User"))
56-
personalization2.add_substitution(Substitution("%city%", "Denver"))
57-
personalization2.add_custom_arg(CustomArg("user_id", "343"))
58-
personalization2.add_custom_arg(CustomArg("type", "marketing"))
59-
personalization2.send_at = 1443636843
60-
mail.add_personalization(personalization2)
32+
for bcc_addr in personalization['bcc_list']:
33+
personalization.add_bc(bcc_addr)
6134

62-
mail.add_content(Content("text/plain", "some text here"))
63-
mail.add_content(Content("text/html", "<html><body>some text here</body></html>"))
35+
for header in personalization['headers']:
36+
personalization.add_header(header)
37+
38+
for substitution in personalization['substitutions']:
39+
personalization.add_substitution(substitution)
40+
41+
for arg in personalization['custom_args']:
42+
personalization.add_custom_arg(arg)
43+
44+
personalization.subject = personalization['subject']
45+
personalization.send_at = personalization['send_at']
46+
return mock_personalization
47+
48+
49+
def get_mock_personalization_dict():
50+
"""Get a dict of personalization mock."""
51+
mock_pers = dict()
52+
53+
mock_pers['to_list'] = [Email("test1@example.com",
54+
"Example User"),
55+
Email("test2@example.com",
56+
"Example User")]
57+
58+
mock_pers['cc_list'] = [Email("test3@example.com",
59+
"Example User"),
60+
Email("test4@example.com",
61+
"Example User")]
62+
63+
mock_pers['bcc_list'] = [Email("test5@example.com"),
64+
Email("test6@example.com")]
6465

66+
mock_pers['subject'] = ("Hello World from the Personalized "
67+
"SendGrid Python Library")
68+
69+
mock_pers['headers'] = [Header("X-Test", "test"),
70+
Header("X-Mock", "true")]
71+
72+
mock_pers['substitutions'] = [Substitution("%name%", "Example User"),
73+
Substitution("%city%", "Denver")]
74+
75+
mock_pers['custom_args'] = [CustomArg("user_id", "343"),
76+
CustomArg("type", "marketing")]
77+
78+
mock_pers['send_at'] = 1443636843
79+
return mock_pers
80+
81+
82+
def build_attachment1():
83+
"""Build attachment mock."""
6584
attachment = Attachment()
66-
attachment.content = "TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdC4gQ3JhcyBwdW12"
85+
attachment.content = ("TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNl"
86+
"Y3RldHVyIGFkaXBpc2NpbmcgZWxpdC4gQ3JhcyBwdW12")
6787
attachment.type = "application/pdf"
6888
attachment.filename = "balance_001.pdf"
6989
attachment.disposition = "attachment"
7090
attachment.content_id = "Balance Sheet"
71-
mail.add_attachment(attachment)
91+
return attachment
92+
93+
94+
def build_attachment2():
95+
"""Build attachment mock."""
96+
attachment = Attachment()
97+
attachment.content = "BwdW"
98+
attachment.type = "image/png"
99+
attachment.filename = "banner.png"
100+
attachment.disposition = "inline"
101+
attachment.content_id = "Banner"
102+
return attachment
103+
104+
105+
def build_mail_settings():
106+
"""Build mail settings mock."""
107+
mail_settings = MailSettings()
108+
mail_settings.bcc_settings = BCCSettings(True, Email("test@example.com"))
109+
mail_settings.bypass_list_management = BypassListManagement(True)
110+
mail_settings.footer_settings = FooterSettings(True, "Footer Text",
111+
("<html><body>Footer "
112+
"Text</body></html>"))
113+
mail_settings.sandbox_mode = SandBoxMode(True)
114+
mail_settings.spam_check = SpamCheck(True, 1,
115+
"https://spamcatcher.sendgrid.com")
116+
return mail_settings
72117

73-
attachment2 = Attachment()
74-
attachment2.content = "BwdW"
75-
attachment2.type = "image/png"
76-
attachment2.filename = "banner.png"
77-
attachment2.disposition = "inline"
78-
attachment2.content_id = "Banner"
79-
mail.add_attachment(attachment2)
118+
119+
def build_tracking_settings():
120+
"""Build tracking settings mock."""
121+
tracking_settings = TrackingSettings()
122+
tracking_settings.click_tracking = ClickTracking(True, True)
123+
tracking_settings.open_tracking = OpenTracking(True,
124+
("Optional tag to "
125+
"replace with the"
126+
"open image in the "
127+
"body of the message"))
128+
129+
subs_track = SubscriptionTracking(True,
130+
("text to insert into the "
131+
"text/plain portion of the"
132+
" message"),
133+
("<html><body>html to insert "
134+
"into the text/html portion of "
135+
"the message</body></html>"),
136+
("Optional tag to replace with "
137+
"the open image in the body of "
138+
"the message"))
139+
140+
tracking_settings.subscription_tracking = subs_track
141+
tracking_settings.ganalytics = Ganalytics(True, "some source",
142+
"some medium", "some term",
143+
"some_content", "some_campaign")
144+
return tracking_settings
145+
146+
147+
def build_kitchen_sink():
148+
"""All settings set"""
149+
mail = Mail()
150+
151+
mail.from_email = Email("test@example.com", "Example User")
152+
mail.subject = "Hello World from the SendGrid Python Library"
153+
154+
personalization = get_mock_personalization_dict()
155+
mail.add_personalization(build_personalization(personalization))
156+
mail.add_personalization(build_personalization(personalization))
157+
158+
mail.add_content(Content("text/plain", "some text here"))
159+
mail.add_content(Content("text/html", ("<html><body>some text "
160+
"here</body></html>")))
161+
162+
mail.add_attachment(build_attachment1())
163+
mail.add_attachment(build_attachment2())
80164

81165
mail.template_id = "13b8f94f-bcae-4ec6-b752-70d6cb59f932"
82166

@@ -94,32 +178,18 @@ def build_kitchen_sink():
94178

95179
mail.send_at = 1443636842
96180

97-
# This must be a valid [batch ID](https://sendgrid.com/docs/API_Reference/SMTP_API/scheduling_parameters.html) to work
181+
# This must be a valid [batch ID]
182+
# (https://sendgrid.com/docs/API_Reference/SMTP_API/scheduling_parameters.html) to work
98183
# mail.set_batch_id("N2VkYjBjYWItMGU4OC0xMWU2LWJhMzYtZjQ1Yzg5OTBkNzkxLWM5ZTUyZjNhOA")
99-
100184
mail.asm = ASM(99, [4, 5, 6, 7, 8])
101-
102185
mail.ip_pool_name = "24"
103-
104-
mail_settings = MailSettings()
105-
mail_settings.bcc_settings = BCCSettings(True, Email("test@example.com"))
106-
mail_settings.bypass_list_management = BypassListManagement(True)
107-
mail_settings.footer_settings = FooterSettings(True, "Footer Text", "<html><body>Footer Text</body></html>")
108-
mail_settings.sandbox_mode = SandBoxMode(True)
109-
mail_settings.spam_check = SpamCheck(True, 1, "https://spamcatcher.sendgrid.com")
110-
mail.mail_settings = mail_settings
111-
112-
tracking_settings = TrackingSettings()
113-
tracking_settings.click_tracking = ClickTracking(True, True)
114-
tracking_settings.open_tracking = OpenTracking(True, "Optional tag to replace with the open image in the body of the message")
115-
tracking_settings.subscription_tracking = SubscriptionTracking(True, "text to insert into the text/plain portion of the message", "<html><body>html to insert into the text/html portion of the message</body></html>", "Optional tag to replace with the open image in the body of the message")
116-
tracking_settings.ganalytics = Ganalytics(True, "some source", "some medium", "some term", "some_content", "some_campaign")
117-
mail.tracking_settings = tracking_settings
118-
186+
mail.mail_settings = build_mail_settings()
187+
mail.tracking_settings = build_tracking_settings()
119188
mail.reply_to = Email("test@example.com")
120189

121190
return mail.get()
122191

192+
123193
def send_hello_email():
124194
# Assumes you set your environment variable:
125195
# https://github.com/sendgrid/sendgrid-python/blob/master/TROUBLESHOOTING.md#environment-variables-and-your-sendgrid-api-key
@@ -130,6 +200,7 @@ def send_hello_email():
130200
print(response.headers)
131201
print(response.body)
132202

203+
133204
def send_kitchen_sink():
134205
# Assumes you set your environment variable:
135206
# https://github.com/sendgrid/sendgrid-python/blob/master/TROUBLESHOOTING.md#environment-variables-and-your-sendgrid-api-key
@@ -140,5 +211,9 @@ def send_kitchen_sink():
140211
print(response.headers)
141212
print(response.body)
142213

143-
send_hello_email() # this will actually send an email
144-
send_kitchen_sink() # this will only send an email if you set SandBox Mode to False
214+
215+
# this will actually send an email
216+
send_hello_email()
217+
218+
# this will only send an email if you set SandBox Mode to False
219+
send_kitchen_sink()

0 commit comments

Comments
 (0)