Skip to content

Commit

Permalink
Add example showing how to read mail using curl/jq.
Browse files Browse the repository at this point in the history
  • Loading branch information
mjmayer committed Apr 17, 2018
1 parent e22f578 commit 4d86173
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 9 deletions.
31 changes: 31 additions & 0 deletions getting_started/step_by_step/text_message
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Enjoy odoo partnership program and success pack sales combo! *
Summer is around the corner! Odoo wishes  to save your time and effort from complicated paperwork for more outdoor activities!  Therefore, we are offering an exclusive discount for Partnership in MAY.
Partnership program pricing at USD 2950
* and save USD 1000* on your joining!
* *The discount offer is only applicable for the purchase with a success pack.


Schedule a demo with
Odoo Partnership Expert* BOOK NOW [2]
Our Partnership
Program* READ MORE [3]
* Our Worldwide Partners* READ MORE [4]
* Our Customers success story* READ MORE [5]
None [6] None [7] None [8] None [9]
Unsubscribe [10] | Contact [11]
2018 All Rights Reserved



[1] https://www.odoo.com/r/erT/m/12928017
[2] https://www.odoo.com/r/X6Q/m/12928017
[3] https://www.odoo.com/r/so8/m/12928017
[4] https://www.odoo.com/r/fya/m/12928017
[5] https://www.odoo.com/r/jlI/m/12928017
[6] https://www.odoo.com/r/dlt/m/12928017
[7] https://www.odoo.com/r/25S/m/12928017
[8] https://www.odoo.com/r/Vcu/m/12928017
[9] https://www.odoo.com/r/nKf/m/12928017
[10] https://www.odoo.com/unsubscribe_from_list
[11] https://www.odoo.com/r/rox/m/12928017

53 changes: 44 additions & 9 deletions getting_started/step_by_step/yougotmail.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,63 @@ You Got Mail!

Now that curl and jq are installed we can start interacting with mailsac. The
`MailSac API Documentation <https://mailsac.com/docs/api/>`_ includes all the
endpoints supported. In this example we are going to check an abritrary email address
endpoints supported. The API documentation is great to use if you a familiar with
REST APIs or for reference after completing this step-by-step introduction. In
this example we are going to check an abritrary email address
for mail, read that email and respond to the email.

Check Mail
----------

In this example we are going to be checking mail for the address `admin@mailsac.com`.
We will be using
the `List Inbox Email Messages <https://mailsac.com/docs/api/#list-inbox-email-messages>`_ endpoint.
Documentation shows this endpoint can be accessed with :code:`GET /api/addresses/:email/messages`. We
In this example I'll show you how to check mail sent `admin@mailsac.com` using curl and JQ.
You will first need to retrieve messages using the
`List Inbox Email Messages endpoint <https://mailsac.com/docs/api/#list-inbox-email-messages>`_.
This endpoint can be accessed with :code:`GET /api/addresses/:email/messages`. You
will substitue `:email` with `admin@mailsac.com` giving us :code:`GET /api/addresses/admin@mailsac.com/messages`.
Curl does not encode URLs for us, so the `@` character needs to be url encoded as `%40` giving us
:code:`GET /api/addresses/admin%40mailsac.com/messages`. The base URI of the mailsac API is mailsac.com, which gives
us the full URL :code:`https://mailsac.com/api/addresses/admin%40mailsac.com/messages`
Curl does not encode URLs. The `@` character needs to be url encoded as `%40` giving.
:code:`GET /api/addresses/admin%40mailsac.com/messages`. The base URI of the mailsac API is mailsac.com, which
translates to :code:`https://mailsac.com/api/addresses/admin%40mailsac.com/messages`

.. tip:: You can validate the url is properly formatted by accessing it in your web browser. Go ahead and try it with
our `example <https://mailsac.com/api/addresses/admin%40mailsac.com/messages>`_ or try it with a different email address.

Curl requires us to add a few extra parameters. `-X GET` instructs curl to us a HTTP GET request. `-s` supresses
a progress bar. In the command below we pipe the contents of curl into JQ for json formatting. JQ requires a filter to function.
We are using the simplest filter `"."` which matches all json.
We are using the simplest filter `"."` which matches all json. `admin@mailsac` is a popular address and receives lots of email.
JQ will only show the first json object with the filter `".[0]"`

.. literalinclude:: /about/intro_curl.bash
:language: bash
:caption: **Retrieve first email in a an inbox.**
:lines: 1


.. literalinclude:: /about/intro_curl.bash
:language: bash
:caption: **Inbox message**
:emphasize-lines: 1
:lines: 2-35,49-51

As you can see, the JSON contains information about the email message including to address,
from address, subject, timestamp, attachments and much more. Make note of the `_id` field, you
will use it to view the contents of the email.

Read Mail
---------

To read a plain text email message you use the `text endpoint <https://mailsac.com/docs/api/#get-message-text>`_.
This endpoint can be accessed by :code:`GET /api/text/:email/:messageId`. You will substitue in the email address
the email was sent to and the message ID for that email. Using the values from the previous section will yield,
:code:`GET /api/text/admin%40mailsac.com:BotvTxaona7gLID1Adtpfj8Fnfi7HSSv-0`. The email message can be retrieved
using curl.

.. code-block:: bash
:caption: **Retrieve text of message**
curl -s -X GET https://mailsac.com/api/text/admin%40mailsac.com/Jn1wa9AwLigQwIbwUGyMMollJkeWSeUd-0
.. literalinclude:: text_message
:language: text
:caption: **Plain text message**


0 comments on commit 4d86173

Please sign in to comment.