Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 28 additions & 12 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Example

import sendgrid

sg = sendgrid.SendGridClient('YOUR_SENDGRID_USERNAME', 'YOUR_SENDGRID_PASSWORD')
sg = sendgrid.SendGridClient('YOUR_SENDGRID_API_KEY')

message = sendgrid.Mail()
message.add_to('John Doe <john@email.com>')
Expand Down Expand Up @@ -245,7 +245,7 @@ List all API Keys belonging to the authenticated user.

.. code:: python

client = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
client = sendgrid.SendGridAPIClient('SENDGRID_API_KEY')
status, msg = client.apikeys.get()

Generate a new API Key for the authenticated user
Expand Down Expand Up @@ -287,7 +287,7 @@ Retrieve all suppression groups associated with the user.

.. code:: python

client = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
client = sendgrid.SendGridAPIClient('SENDGRID_API_KEY')
status, msg = client.asm_groups.get()

Get a single record.
Expand All @@ -311,9 +311,9 @@ Add recipient addresses to the suppressions list for a given group.

.. code:: python

client = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
client = sendgrid.SendGridAPIClient('SENDGRID_API_KEY')
group_id = <group_id_number> # If no group_id_number, the emails will be added to the global suppression group
emails = ['elmer+test@thinkingserious.com', 'elmer+test2@thinkingserious.com']
emails = ['example@example.com', 'example@example.com']
status, msg = client.asm_suppressions.post(group_id, emails)

Get suppressed addresses for a given group.
Expand All @@ -337,28 +337,28 @@ Check if a given email is on the global suppression list.

.. code:: python

client = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
email = ['elmer@thinkingserious.com']
client = sendgrid.SendGridAPIClient('SENDGRID_API_KEY')
email = ['example@example.com']
status, msg = client.asm_global_suppressions.get(email)

Get a list of all SendGrid globally unsubscribed emails.

.. code:: python
client = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
client = sendgrid.SendGridAPIClient('SENDGRID_API_KEY')
status, msg = client.suppressions.get()

Add an email to the global suppression list.

.. code:: python
client = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
email = ['elmer@thinkingserious.com']
client = sendgrid.SendGridAPIClient('SENDGRID_API_KEY')
email = ['example@example.com']
status, msg = client.asm_global_suppressions.post(email)

Delete an email from the global suppression list.

.. code:: python
client = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
email = 'elmer@thinkingserious.com'
client = sendgrid.SendGridAPIClient('SENDGRID_API_KEY')
email = 'example@example.com'
status, msg = client.asm_global_suppressions.delete(email)

SendGrid's `X-SMTPAPI`_
Expand All @@ -369,6 +369,21 @@ If you wish to use the X-SMTPAPI on your own app, you can use the

There are implementations for setter methods too.

Example
~~~~~~~

.. code:: python

sg = sendgrid.SendGridClient('SENDGRID_API_KEY')
message = sendgrid.Mail()
message.add_substitution(':first_name', 'John')
message.smtpapi.add_to('John <example@example.com>')
message.set_subject('Testing from the Python library using the SMTPAPI')
message.set_html('<b>:first_name, this was a successful test of using the SMTPAPI library!</b>')
message.set_text(':name, this was a successful test of using the SMTPAPI library!')
message.set_from('Jane <example@example.com>')
sg.send(message)

`Recipients`_
~~~~~~~~~~~~~

Expand Down Expand Up @@ -512,6 +527,7 @@ Using Templates from the Template Engine

message.add_filter('templates', 'enable', '1')
message.add_filter('templates', 'template_id', 'TEMPLATE-ALPHA-NUMERIC-ID')
message.add_substitution('key', 'value')

Tests
~~~~~
Expand Down
53 changes: 47 additions & 6 deletions example_v2_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,59 @@
if len(var) == 2:
os.environ[var[0]] = var[1]

sg = sendgrid.SendGridClient(os.environ.get('SENDGRID_USERNAME'), os.environ.get('SENDGRID_PASSWORD'))
sg = sendgrid.SendGridClient(os.environ.get('SENDGRID_API_KEY'))

"""
to = 'Jane Doe <example@example.com>'
from = 'John Doe <example@example.com>'
# Basic Send Example

message = sendgrid.Mail()
message.add_to(to)
message.add_to('John Doe <example@example.com>')
message.set_subject('Testing from the Python library')
message.set_html('<b>This was a successful test!</b>')
message.set_text('This was a successful test!')
message.set_from(from)
message.set_from('Jane Doe <example@example.com')
status, msg = sg.send(message)
print status
print msg

# SMTPAPI Basic Send Example

message = sendgrid.Mail()
message.add_substitution(':first_name', 'John')
message.smtpapi.add_to('John Doe <example@example.com>')
message.set_subject('Testing from the Python library using the SMTPAPI')
message.set_html('<b>:first_name, this was a successful test of using the SMTPAPI library!</b>')
message.set_text(':name, this was a successful test of using the SMTPAPI library!')
message.set_from('Jane Doe <example@example.com>')
status, msg = sg.send(message)
print status
print msg
"""

# Template Engine Example
# In the template editor, the subject is <%subject%> and the body is:
#
# Hello :name,
#
# <%body%>
#
# With Best Regards,
#
# Your Library Tester
#
# <%subject%> is replaced with the value in message.set_subject
# <%body%> is replaced with the value in message.set_html and message.set_text
# :name is replaced with the value in message.add_substitution

message = sendgrid.Mail()
message.add_filter('templates', 'enable', '1')
message.add_filter('templates', 'template_id', 'TEMPLATE-ALPHA-NUMERIC-ID')
message.add_substitution(':name', 'John')
message.add_to('John Doe <example@example.com')
message.set_subject('Testing from the Python library using the SMTPAPI')
message.set_html('<b>This was a successful test of using the SMTPAPI library!</b>')
message.set_text('This was a successful test of using the SMTPAPI library!')
message.set_from('Jane Doe <example@example.com>')
status, msg = sg.send(message)
print status
print msg
"""