Showing Emails in OnePageCRM Mobile
Here at OnePageCRM, we always want to bring more functionality to the mobile applications. Being able to see emails and their attachments was one of the features that has been requested for a long time.
The most recent update for the iOS application, added this much anticipated possibility.
As an iOS developer here at OnePageCRM I will explain the steps we took to add this functionality to the iOS application.
The first thing that we needed to change, to be able to add this functionality, was a new API endpoint: /api/v3/contacts/{contact_id}/email_messages.json
The response from this endpoint, contains an array of email messages, which would look something like the following:
{
"email_messages": [
{
"email_message": {
"id": "5bdb11681787fabbe683b1eb",
"type": "email_send",
"contact_ids": [
"58edfbf600d4af9e3b7e93e9"
],
"send_time": "2018-11-01T14:44:56Z",
"message_id": "CADVjCOqcL=e_-cEjNfevrR7-yp3xKmnxsvamJfps_xqtDFv8bA@mail.gmail.com",
"sender": "blog@bigcompany.co.uk",
"recipients": {
"to": [
"jbloggs@bigcompany.co.uk"
],
"cc": [],
"bcc": []
},
"url": "",
"subject": "RED DEAD REDEMPTION 2 REVIEW",
"plain_content": "Red Dead Redemption 2 is a sprawling Western tale of loyalty... So let’s start at the beginning: It’s 1899 and American outlaws are an endangered species...",
"html_content": "<div style=\"font-family: sans-serif, Arial, Helvetica\"><a href=\"https://www.ign.com/games/red-dead-redemption-2\" target=\"_blank\" rel=\"noopener noreferrer\">Red Dead Redemption 2</a> is a sprawling Western tale of loyalty...<br/><br/><br/><img src='https://onepagecrm-up-sa-east-1.s3.sa-east-1.amazonaws.com/58edfbf600d4af9e3b7e93e9/1541083454780/rdr2-screenshot-110-1540464386332.jpg' width=auto height=auto />So let’s start at the beginning: It’s 1899 and American outlaws are an endangered species....</div>",
"status": "sent",
"incoming_email": false,
"attachments": []
}
}
]}
It’s important to highlight 4 fields from the above JSON:
- html_content: The content of the email (with html tags for formatting).
- plain_content: The content of the email (without any formatting).
- type: The type of email (it can be "email_send"
or "bcc_email"
). The first one is for when you send an email from within OnePageCRM, the second is when the email is captured by the email dropbox method (BCC).
- url: This field contains a link (only when the email is of type bcc_email). For this type of email, the "html_content"
is empty, and to get the content with tags it’s necessary to request the content from this url.
The email layout in the OnePageCRM mobile app is a little different from the "html_content"
in the JSON. We have to parse and rearrange the string "html_content"
, in order to display it on the screen.
To show the email’s content for the user, we use the WKWebView view. This view is a type of web view that can show HTML tags with the correct formatting. Emails have text, images, font, colors and attachments - the app needs to show all of them.
Because of the attachments, the web view is in the first section of a table. The second section shows attachments (like deals, notes or calls). The content of the attachments is in the attachments JSON array. The fields in the JSON are the same as in other endpoints (deals, notes or calls).
Ray Tomlinson in the 60s probably never thought that his invention would help to change the world. Today it’s impossible to live without emails, and to be able to see your emails with each contact, will help you to ensure you don’t miss anything while on the go.
If you’ve any questions or ideas for my next blog post. Let us know in the comments or in our forum.