diff --git a/README.rst b/README.rst index 3b79e1c2e..b4abb4f2f 100644 --- a/README.rst +++ b/README.rst @@ -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 ') @@ -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 @@ -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. @@ -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 = # 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. @@ -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`_ @@ -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 ') + message.set_subject('Testing from the Python library using the SMTPAPI') + message.set_html(':first_name, this was a successful test of using the SMTPAPI library!') + message.set_text(':name, this was a successful test of using the SMTPAPI library!') + message.set_from('Jane ') + sg.send(message) + `Recipients`_ ~~~~~~~~~~~~~ @@ -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 ~~~~~ diff --git a/example_v2_test.py b/example_v2_test.py index ec8c6219b..fb2a554d9 100755 --- a/example_v2_test.py +++ b/example_v2_test.py @@ -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 ' -from = 'John Doe ' +# Basic Send Example + message = sendgrid.Mail() -message.add_to(to) +message.add_to('John Doe ') message.set_subject('Testing from the Python library') message.set_html('This was a successful test!') message.set_text('This was a successful test!') -message.set_from(from) +message.set_from('Jane Doe ') +message.set_subject('Testing from the Python library using the SMTPAPI') +message.set_html(':first_name, this was a successful test of using the SMTPAPI library!') +message.set_text(':name, this was a successful test of using the SMTPAPI library!') +message.set_from('Jane Doe ') status, msg = sg.send(message) print status print msg -""" \ No newline at end of file + +# 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 This was a successful test of using the SMTPAPI library!') +message.set_text('This was a successful test of using the SMTPAPI library!') +message.set_from('Jane Doe ') +status, msg = sg.send(message) +print status +print msg +"""