@@ -37,7 +37,7 @@ Example
37
37
38
38
import sendgrid
39
39
40
- sg = sendgrid.SendGridClient(' YOUR_SENDGRID_USERNAME ' , ' YOUR_SENDGRID_PASSWORD ' )
40
+ sg = sendgrid.SendGridClient(' YOUR_SENDGRID_API_KEY ' )
41
41
42
42
message = sendgrid.Mail()
43
43
message.add_to(' John Doe <[email protected] >' )
@@ -245,7 +245,7 @@ List all API Keys belonging to the authenticated user.
245
245
246
246
.. code :: python
247
247
248
- client = sendgrid.SendGridAPIClient(os.environ.get( ' SENDGRID_API_KEY' ) )
248
+ client = sendgrid.SendGridAPIClient(' SENDGRID_API_KEY' )
249
249
status, msg = client.apikeys.get()
250
250
251
251
Generate a new API Key for the authenticated user
@@ -287,7 +287,7 @@ Retrieve all suppression groups associated with the user.
287
287
288
288
.. code :: python
289
289
290
- client = sendgrid.SendGridAPIClient(os.environ.get( ' SENDGRID_API_KEY' ) )
290
+ client = sendgrid.SendGridAPIClient(' SENDGRID_API_KEY' )
291
291
status, msg = client.asm_groups.get()
292
292
293
293
Get a single record.
@@ -311,9 +311,9 @@ Add recipient addresses to the suppressions list for a given group.
311
311
312
312
.. code :: python
313
313
314
- client = sendgrid.SendGridAPIClient(os.environ.get( ' SENDGRID_API_KEY' ) )
314
+ client = sendgrid.SendGridAPIClient(' SENDGRID_API_KEY' )
315
315
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' ]
317
317
status, msg = client.asm_suppressions.post(group_id, emails)
318
318
319
319
Get suppressed addresses for a given group.
@@ -337,28 +337,28 @@ Check if a given email is on the global suppression list.
337
337
338
338
.. code :: python
339
339
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' ]
342
342
status, msg = client.asm_global_suppressions.get(email)
343
343
344
344
Get a list of all SendGrid globally unsubscribed emails.
345
345
346
346
.. code :: python
347
- client = sendgrid.SendGridAPIClient(os.environ.get( ' SENDGRID_API_KEY' ) )
347
+ client = sendgrid.SendGridAPIClient(' SENDGRID_API_KEY' )
348
348
status, msg = client.suppressions.get()
349
349
350
350
Add an email to the global suppression list.
351
351
352
352
.. 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' ]
355
355
status, msg = client.asm_global_suppressions.post(email)
356
356
357
357
Delete an email from the global suppression list.
358
358
359
359
.. 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'
362
362
status, msg = client.asm_global_suppressions.delete(email)
363
363
364
364
SendGrid's `X-SMTPAPI `_
@@ -369,6 +369,21 @@ If you wish to use the X-SMTPAPI on your own app, you can use the
369
369
370
370
There are implementations for setter methods too.
371
371
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
+
372
387
`Recipients `_
373
388
~~~~~~~~~~~~~
374
389
@@ -512,6 +527,7 @@ Using Templates from the Template Engine
512
527
513
528
message.add_filter(' templates' , ' enable' , ' 1' )
514
529
message.add_filter(' templates' , ' template_id' , ' TEMPLATE-ALPHA-NUMERIC-ID' )
530
+ message.add_substitution(' key' , ' value' )
515
531
516
532
Tests
517
533
~~~~~
0 commit comments