Skip to content

Commit f11eab4

Browse files
Merge pull request #147 from sendgrid/139-smtpapi-doc-update
139 smtpapi doc update
2 parents 021f045 + cc24a6f commit f11eab4

File tree

2 files changed

+75
-18
lines changed

2 files changed

+75
-18
lines changed

README.rst

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Example
3737
3838
import sendgrid
3939
40-
sg = sendgrid.SendGridClient('YOUR_SENDGRID_USERNAME', 'YOUR_SENDGRID_PASSWORD')
40+
sg = sendgrid.SendGridClient('YOUR_SENDGRID_API_KEY')
4141
4242
message = sendgrid.Mail()
4343
message.add_to('John Doe <[email protected]>')
@@ -245,7 +245,7 @@ List all API Keys belonging to the authenticated user.
245245

246246
.. code:: python
247247
248-
client = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
248+
client = sendgrid.SendGridAPIClient('SENDGRID_API_KEY')
249249
status, msg = client.apikeys.get()
250250
251251
Generate a new API Key for the authenticated user
@@ -287,7 +287,7 @@ Retrieve all suppression groups associated with the user.
287287

288288
.. code:: python
289289
290-
client = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
290+
client = sendgrid.SendGridAPIClient('SENDGRID_API_KEY')
291291
status, msg = client.asm_groups.get()
292292
293293
Get a single record.
@@ -311,9 +311,9 @@ Add recipient addresses to the suppressions list for a given group.
311311

312312
.. code:: python
313313
314-
client = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
314+
client = sendgrid.SendGridAPIClient('SENDGRID_API_KEY')
315315
group_id = <group_id_number> # If no group_id_number, the emails will be added to the global suppression group
316-
emails = ['elmer+test@thinkingserious.com', 'elmer+test2@thinkingserious.com']
316+
emails = ['example@example.com', 'example@example.com']
317317
status, msg = client.asm_suppressions.post(group_id, emails)
318318
319319
Get suppressed addresses for a given group.
@@ -337,28 +337,28 @@ Check if a given email is on the global suppression list.
337337

338338
.. code:: python
339339
340-
client = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
341-
email = ['elmer@thinkingserious.com']
340+
client = sendgrid.SendGridAPIClient('SENDGRID_API_KEY')
341+
email = ['example@example.com']
342342
status, msg = client.asm_global_suppressions.get(email)
343343
344344
Get a list of all SendGrid globally unsubscribed emails.
345345

346346
.. code:: python
347-
client = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
347+
client = sendgrid.SendGridAPIClient('SENDGRID_API_KEY')
348348
status, msg = client.suppressions.get()
349349
350350
Add an email to the global suppression list.
351351

352352
.. code:: python
353-
client = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
354-
email = ['elmer@thinkingserious.com']
353+
client = sendgrid.SendGridAPIClient('SENDGRID_API_KEY')
354+
email = ['example@example.com']
355355
status, msg = client.asm_global_suppressions.post(email)
356356
357357
Delete an email from the global suppression list.
358358

359359
.. code:: python
360-
client = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
361-
email = 'elmer@thinkingserious.com'
360+
client = sendgrid.SendGridAPIClient('SENDGRID_API_KEY')
361+
email = 'example@example.com'
362362
status, msg = client.asm_global_suppressions.delete(email)
363363
364364
SendGrid's `X-SMTPAPI`_
@@ -369,6 +369,21 @@ If you wish to use the X-SMTPAPI on your own app, you can use the
369369

370370
There are implementations for setter methods too.
371371

372+
Example
373+
~~~~~~~
374+
375+
.. code:: python
376+
377+
sg = sendgrid.SendGridClient('SENDGRID_API_KEY')
378+
message = sendgrid.Mail()
379+
message.add_substitution(':first_name', 'John')
380+
message.smtpapi.add_to('John <[email protected]>')
381+
message.set_subject('Testing from the Python library using the SMTPAPI')
382+
message.set_html('<b>:first_name, this was a successful test of using the SMTPAPI library!</b>')
383+
message.set_text(':name, this was a successful test of using the SMTPAPI library!')
384+
message.set_from('Jane <[email protected]>')
385+
sg.send(message)
386+
372387
`Recipients`_
373388
~~~~~~~~~~~~~
374389

@@ -512,6 +527,7 @@ Using Templates from the Template Engine
512527
513528
message.add_filter('templates', 'enable', '1')
514529
message.add_filter('templates', 'template_id', 'TEMPLATE-ALPHA-NUMERIC-ID')
530+
message.add_substitution('key', 'value')
515531
516532
Tests
517533
~~~~~

example_v2_test.py

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,59 @@
66
if len(var) == 2:
77
os.environ[var[0]] = var[1]
88

9-
sg = sendgrid.SendGridClient(os.environ.get('SENDGRID_USERNAME'), os.environ.get('SENDGRID_PASSWORD'))
9+
sg = sendgrid.SendGridClient(os.environ.get('SENDGRID_API_KEY'))
1010

1111
"""
12-
to = 'Jane Doe <[email protected]>'
13-
from = 'John Doe <[email protected]>'
12+
# Basic Send Example
13+
1414
message = sendgrid.Mail()
15-
message.add_to(to)
15+
message.add_to('John Doe <[email protected]>')
1616
message.set_subject('Testing from the Python library')
1717
message.set_html('<b>This was a successful test!</b>')
1818
message.set_text('This was a successful test!')
19-
message.set_from(from)
19+
message.set_from('Jane Doe <[email protected]')
20+
status, msg = sg.send(message)
21+
print status
22+
print msg
23+
24+
# SMTPAPI Basic Send Example
25+
26+
message = sendgrid.Mail()
27+
message.add_substitution(':first_name', 'John')
28+
message.smtpapi.add_to('John Doe <[email protected]>')
29+
message.set_subject('Testing from the Python library using the SMTPAPI')
30+
message.set_html('<b>:first_name, this was a successful test of using the SMTPAPI library!</b>')
31+
message.set_text(':name, this was a successful test of using the SMTPAPI library!')
32+
message.set_from('Jane Doe <[email protected]>')
2033
status, msg = sg.send(message)
2134
print status
2235
print msg
23-
"""
36+
37+
# Template Engine Example
38+
# In the template editor, the subject is <%subject%> and the body is:
39+
#
40+
# Hello :name,
41+
#
42+
# <%body%>
43+
#
44+
# With Best Regards,
45+
#
46+
# Your Library Tester
47+
#
48+
# <%subject%> is replaced with the value in message.set_subject
49+
# <%body%> is replaced with the value in message.set_html and message.set_text
50+
# :name is replaced with the value in message.add_substitution
51+
52+
message = sendgrid.Mail()
53+
message.add_filter('templates', 'enable', '1')
54+
message.add_filter('templates', 'template_id', 'TEMPLATE-ALPHA-NUMERIC-ID')
55+
message.add_substitution(':name', 'John')
56+
message.add_to('John Doe <[email protected]')
57+
message.set_subject('Testing from the Python library using the SMTPAPI')
58+
message.set_html('<b>This was a successful test of using the SMTPAPI library!</b>')
59+
message.set_text('This was a successful test of using the SMTPAPI library!')
60+
message.set_from('Jane Doe <[email protected]>')
61+
status, msg = sg.send(message)
62+
print status
63+
print msg
64+
"""

0 commit comments

Comments
 (0)