{"id":11895,"date":"2018-12-16T09:09:44","date_gmt":"2018-12-16T17:09:44","guid":{"rendered":"https:\/\/www.seedcode.com\/?p=11895"},"modified":"2023-02-02T15:24:20","modified_gmt":"2023-02-02T15:24:20","slug":"email-threads-filemaker-gmail","status":"publish","type":"post","link":"https:\/\/seedcode.com\/email-threads-filemaker-gmail\/","title":{"rendered":"Integrating FileMaker and Gmail Part 3 \u2013 Email Threads"},"content":{"rendered":"<p>This is the third and final post in a series on using the Gmail API from FileMaker. Please review the previous articles, if you haven\u2019t already, particularly the first one which covers setting your app up with Google and authentication. There\u2019s also a great article by Brendan McBride from <a href=\"https:\/\/dbservices.com\/\" target=\"_blank\" rel=\"noopener noreferrer\"><span class=\"s2\">dbservices<\/span><\/a> that covers importing emails from an inbox into FileMaker. This article can be seen as the first in the series as it leads directly to the ones we\u2019ve done here.<\/p>\n<p class=\"p1\" style=\"padding-left: 30px;\"><span class=\"s2\"><a href=\"https:\/\/www.seedcode.com\/html-email-filemaker-gmail\/\" target=\"_blank\" rel=\"noopener noreferrer\">Integrating FileMaker and Gmail Part 1 \u2013 Sending HTML Emails<\/a><\/span><\/p>\n<p class=\"p1\" style=\"padding-left: 30px;\"><span class=\"s2\"><a href=\"https:\/\/www.seedcode.com\/filemaker-gmail-email-attachments\/\" target=\"_blank\" rel=\"noopener noreferrer\">Integrating FileMaker and Gmail Part 2 \u2013 Sending Attachments<\/a><\/span><\/p>\n<p class=\"p1\" style=\"padding-left: 30px;\"><span class=\"s2\"><a href=\"https:\/\/dbservices.com\/articles\/filemaker-gmail-integration\/\" target=\"_blank\" rel=\"noopener noreferrer\">dbservices \u2013 FileMaker Gmail Integration<\/a><\/span><\/p>\n<p>As with the first article, all of these examples use the native Insert From URL script step so there won\u2019t be any plug-ins required, and since the Insert From URL is supported in all aspects of the FileMaker platform,\u00a0<b>these techniques can be adapted to work<\/b>\u00a0<b>on the Server, Go, FileMaker Cloud, and WebDirect.\u00a0<\/b>These techniques require FileMaker 16 or higher as they use the advanced\u00a0<a href=\"https:\/\/fmhelp.filemaker.com\/help\/17\/fmp\/en\/index.html#page\/FMP_Help%2Fcurl-options.html%23ww1127302\" target=\"_blank\" rel=\"noopener noreferrer\"><span class=\"s3\">cURL options<\/span><\/a>\u00a0introduced in that version.<\/p>\n<h2 class=\"p1\"><span class=\"s1\">Working With Threads<\/span><\/h2>\n<p class=\"p1\"><span class=\"s1\">This article will be looking at working with email threads. It will cover querying for responses to a specific thread of emails and maintaining the thread correctly when responding to an email from FileMaker. Here\u2019s a video overview along with a new free example file below:<\/span><\/p>\n<p><iframe title=\"Integrating FileMaker and Gmail Part 3 &amp;ndash; Email Threads\" src=\"https:\/\/player.vimeo.com\/video\/306609057?h=ceeba93d17&amp;dnt=1&amp;app_id=122963\" width=\"960\" height=\"540\" frameborder=\"0\" allow=\"autoplay; fullscreen; picture-in-picture\" allowfullscreen><\/iframe><\/p>\n<h2 class=\"p1\"><span class=\"s1\"><b>FileMaker Gmail Integration: Example File<\/b><\/span><\/h2>\n<p class=\"p1\"><span class=\"s1\">Please download the example file\u00a0<a href=\"\/wp-content\/uploads\/2018\/12\/FM2Gmail_Part3.zip\" rel=\"noreferrer\">FM2Gmail v1.31<\/a>\u00a0for a working demo. This new version adds the ability to receive incoming messages for existing threads and reply to them. This file replaces v1.2 from the\u00a0previous article. File updated July 19th, 2019.<\/span><\/p>\n<figure id=\"attachment_11898\" aria-describedby=\"caption-attachment-11898\" style=\"width: 898px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.seedcode.com\/wp-content\/uploads\/2018\/12\/Example-File.png\" target=\"_blank\" rel=\"noopener\"><img fetchpriority=\"high\" decoding=\"async\" class=\"wp-image-11898 size-full\" src=\"https:\/\/www.seedcode.com\/wp-content\/uploads\/2018\/12\/Example-File.png\" alt=\"FileMaker Gmail Integration Example File\" width=\"898\" height=\"947\" srcset=\"https:\/\/seedcode.com\/wp-content\/uploads\/2018\/12\/Example-File.png 898w, https:\/\/seedcode.com\/wp-content\/uploads\/2018\/12\/Example-File-284x300.png 284w, https:\/\/seedcode.com\/wp-content\/uploads\/2018\/12\/Example-File-768x810.png 768w\" sizes=\"(max-width: 898px) 100vw, 898px\" \/><\/a><figcaption id=\"caption-attachment-11898\" class=\"wp-caption-text\">Latest FM2Gmail Example File<\/figcaption><\/figure>\n<h2 class=\"p1\"><span class=\"s1\">Managing Replies<\/span><\/h2>\n<p class=\"p1\"><span class=\"s1\">At the end of our last example, we had successfully sent an HTML email with multiple attachments, but what if the correspondent responds to the message? If we want our outgoing message to be associated with a specific FileMaker record, then it\u2019s likely we\u2019ll want all the responses to this email, and all subsequent responses, to be associated with this record as well. Let\u2019s look at this in action. I\u2019ve sent a message from our example file to myself, and now I\u2019m going to respond and add a new inline attachment to my response.<\/span><!--more--><\/p>\n<figure id=\"attachment_11899\" aria-describedby=\"caption-attachment-11899\" style=\"width: 1024px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.seedcode.com\/wp-content\/uploads\/2018\/12\/Reply.png\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" class=\"wp-image-11899 size-large\" src=\"https:\/\/www.seedcode.com\/wp-content\/uploads\/2018\/12\/Reply-1024x773.png\" alt=\"Replying to an Email Thread Started by FileMaker\" width=\"1024\" height=\"773\" srcset=\"https:\/\/seedcode.com\/wp-content\/uploads\/2018\/12\/Reply-1024x773.png 1024w, https:\/\/seedcode.com\/wp-content\/uploads\/2018\/12\/Reply-300x226.png 300w, https:\/\/seedcode.com\/wp-content\/uploads\/2018\/12\/Reply-768x580.png 768w, https:\/\/seedcode.com\/wp-content\/uploads\/2018\/12\/Reply.png 1146w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption id=\"caption-attachment-11899\" class=\"wp-caption-text\">Replying To A Message Set From FileMaker<\/figcaption><\/figure>\n<p>When you reply to an incoming email from Gmail or any email client, the thread id is maintained, and this keeps all responses in the same thread. If we want to check and see if we have any replies to our outgoing emails, then we can just query those specific threads by the thread id. Any new emails with the same thread id will be new responses to that threat. In our sample file, we can hit the little refresh button on the right and check for replies in just this way.<\/p>\n<figure id=\"attachment_11901\" aria-describedby=\"caption-attachment-11901\" style=\"width: 898px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.seedcode.com\/wp-content\/uploads\/2018\/12\/Response.png\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" class=\"wp-image-11901 size-full\" src=\"https:\/\/www.seedcode.com\/wp-content\/uploads\/2018\/12\/Response.png\" alt=\"Receiving email in a FileMaker inbox\" width=\"898\" height=\"947\" srcset=\"https:\/\/seedcode.com\/wp-content\/uploads\/2018\/12\/Response.png 898w, https:\/\/seedcode.com\/wp-content\/uploads\/2018\/12\/Response-284x300.png 284w, https:\/\/seedcode.com\/wp-content\/uploads\/2018\/12\/Response-768x810.png 768w\" sizes=\"(max-width: 898px) 100vw, 898px\" \/><\/a><figcaption id=\"caption-attachment-11901\" class=\"wp-caption-text\">You&#8217;ve Got Mail<\/figcaption><\/figure>\n<p>After running our refresh, we see our text go bold, and a (1) appended to the correspondent\u2019s name indicating we\u2019ve got one new message in the thread. When we click on that line, we are taken to the newest response in a found set representing the thread.<\/p>\n<figure id=\"attachment_11902\" aria-describedby=\"caption-attachment-11902\" style=\"width: 898px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.seedcode.com\/wp-content\/uploads\/2018\/12\/ReviewReply.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-11902 size-full\" src=\"https:\/\/www.seedcode.com\/wp-content\/uploads\/2018\/12\/ReviewReply.png\" alt=\"Replay to Email in FileMaker\" width=\"898\" height=\"947\" srcset=\"https:\/\/seedcode.com\/wp-content\/uploads\/2018\/12\/ReviewReply.png 898w, https:\/\/seedcode.com\/wp-content\/uploads\/2018\/12\/ReviewReply-284x300.png 284w, https:\/\/seedcode.com\/wp-content\/uploads\/2018\/12\/ReviewReply-768x810.png 768w\" sizes=\"(max-width: 898px) 100vw, 898px\" \/><\/a><figcaption id=\"caption-attachment-11902\" class=\"wp-caption-text\">Reviewing The Reply<\/figcaption><\/figure>\n<p>We also see that the attachment is correctly displaying inline and that we have a new reply button. If we click reply, we\u2019re brought back to our compose screen: but now when we send, we\u2019ll need to make sure we specify our thread id and include a few other headers to make sure the thread is maintained correctly.<\/p>\n<figure id=\"attachment_11903\" aria-describedby=\"caption-attachment-11903\" style=\"width: 812px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.seedcode.com\/wp-content\/uploads\/2018\/12\/Reply-Again.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-11903 size-full\" src=\"https:\/\/www.seedcode.com\/wp-content\/uploads\/2018\/12\/Reply-Again.png\" alt=\"Reply to Email Thread in FileMaker\" width=\"812\" height=\"896\" srcset=\"https:\/\/seedcode.com\/wp-content\/uploads\/2018\/12\/Reply-Again.png 812w, https:\/\/seedcode.com\/wp-content\/uploads\/2018\/12\/Reply-Again-272x300.png 272w, https:\/\/seedcode.com\/wp-content\/uploads\/2018\/12\/Reply-Again-768x847.png 768w\" sizes=\"(max-width: 812px) 100vw, 812px\" \/><\/a><figcaption id=\"caption-attachment-11903\" class=\"wp-caption-text\">Replying To A Reply From FileMaker<\/figcaption><\/figure>\n<p>If we don\u2019t specify the thread id or miss one of the required headers, then the email will still go out, but it will appear in the correspondent\u2019s inbox as a new email, rather than a response to this thread. Fortunately, we&#8217;ve figured that tricky part out for this example file, and we now see our response from FileMaker maintains the thread for the correspondent.<\/p>\n<figure id=\"attachment_11904\" aria-describedby=\"caption-attachment-11904\" style=\"width: 1024px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.seedcode.com\/wp-content\/uploads\/2018\/12\/Inline.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-11904 size-large\" src=\"https:\/\/www.seedcode.com\/wp-content\/uploads\/2018\/12\/Inline-1024x736.png\" alt=\"Threaded Email From FileMaker\" width=\"1024\" height=\"736\" srcset=\"https:\/\/seedcode.com\/wp-content\/uploads\/2018\/12\/Inline-1024x736.png 1024w, https:\/\/seedcode.com\/wp-content\/uploads\/2018\/12\/Inline-300x216.png 300w, https:\/\/seedcode.com\/wp-content\/uploads\/2018\/12\/Inline-768x552.png 768w, https:\/\/seedcode.com\/wp-content\/uploads\/2018\/12\/Inline.png 1152w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption id=\"caption-attachment-11904\" class=\"wp-caption-text\">Message Received Correctly As A Thread Response<\/figcaption><\/figure>\n<h2 class=\"p1\"><span class=\"s1\">Gmail Threads: Under The Hood<\/span><\/h2>\n<h2 class=\"p1\"><span class=\"s1\">Checking A Thread<\/span><\/h2>\n<p class=\"p1\"><span class=\"s1\">As we\u2019ve seen in our previous examples, when an email is successfully sent, we get a simple JSON response like this.<\/span><\/p>\n<pre class=\"\">{\n \"id\": \"167180923a6f9ac3\",\n \"threadId\": \"167180923a6f9ac3\",\n \"labelIds\": [\n \"UNREAD\",\n \"SENT\",\n \"INBOX\"\n ]\n}<\/pre>\n<p class=\"p1\"><span class=\"s1\">One of the properties is the thread id, and for the first email in the thread, the message id and the thread id are the same, as they are in the example above. When we send an email successfully from our example file, we write both values to the email record, so we can use the thread id for future queries.<\/span><\/p>\n<p class=\"p1\"><span class=\"s1\">In our example file, the top level script is <b>Update New Messages<\/b> which loops through all the thread ids for the related emails and goes through 3 potential steps. <\/span><\/p>\n<p class=\"p1\"><span class=\"s1\">The first step is to get a list of all the email messages associated with the thread. We can do a GET to the following URL to get a basic list of the messages. The URL for this is below. Make sure you specify the parameter format as minimal, or we\u2019ll get all the headers and body content of the messages, and we\u2019re not sure which ones are new yet. In all the code examples below, the double brackets represent a variable value to be inserted.<\/span><\/p>\n<pre class=\"\">https:\/\/www.googleapis.com\/gmail\/v1\/users\/me\/threads\/[[$threadId]]\/?format=minimal<\/pre>\n<p>The following cURL option needs to be specified for authentication:<\/p>\n<pre class=\"\">-H \"Authorization: Bearer [[$accessToken]]\"<\/pre>\n<p>And I always include a variable to track the response headers as well:<\/p>\n<pre class=\"\">-D \"$responseHeaders\"<\/pre>\n<p>A successful response is JSON that we can loop through and get a list of the message ids:<\/p>\n<pre class=\"\">{\n  \"id\": \"167b308b2e619a0d\",\n  \"historyId\": \"13543311\",\n  \"messages\": [\n    {\n      \"id\": \"167b308b2e619a0d\",\n      \"threadId\": \"167b308b2e619a0d\",\n      \"labelIds\": [\n        \"SENT\"\n      ],\n      \"snippet\": \"Please see the attached images awaiting your approval. Thank You!\",\n      \"historyId\": \"13543233\",\n      \"internalDate\": \"1544896950000\",\n      \"sizeEstimate\": 4223596\n    },\n    {\n      \"id\": \"167b30a4740e0b44\",\n      \"threadId\": \"167b308b2e619a0d\",\n      \"labelIds\": [\n        \"IMPORTANT\",\n        \"SENT\"\n      ],\n      \"snippet\": \"Those are nice, but please use this one. On Sat, Dec 15, 2018 at 11:02 AM &amp;lt;jason@seedcode.com&amp;gt; wrote: Please see the attached images awaiting your approval. Thank You! -- Jason Young SeedCode LLC\",\n      \"historyId\": \"13543233\",\n      \"internalDate\": \"1544897054000\",\n      \"sizeEstimate\": 1420834\n    }\n  ]\n}<\/pre>\n<p class=\"p1\"><span class=\"s1\">That list is then compared to a list of the message ids that we already have as records in the file: removing those ids we already have. If there are no ids left in the list, then the process ends. Otherwise, it continues on to step 2: getting the email content.<\/span><\/p>\n<h2 class=\"p1\"><span class=\"s1\">Importing an Email<\/span><\/h2>\n<p class=\"p1\"><span class=\"s1\">This part of the process is very similar to what dbservices put together in their example. Brendan covered some of this already, but we\u2019ll go over our process in the context of this example. You can step through the script <b>Get Email <\/b>to see these processes in more detail.<\/span><\/p>\n<p class=\"p1\"><span class=\"s1\">To get the content of an email, we do a GET to a URL that references the email by its message id.<\/span><\/p>\n<pre class=\"\">https:\/\/www.googleapis.com\/gmail\/v1\/users\/me\/messages\/[[$id]]<\/pre>\n<p>And the cURL options needed are the same as the initial GET:<\/p>\n<pre class=\"\">-H \"Authorization: Bearer [[$accessToken]]\"\n-D \"$responseHeaders<\/pre>\n<p class=\"p1\"><span class=\"s1\">A successful response is a large, somewhat complex JSON response, but the paths that we\u2019re looking for are <em>payload.headers<\/em> and <em>payload.parts<\/em>. Both are JSON arrays.<\/span><\/p>\n<p class=\"p1\"><span class=\"s1\">The headers array needs to be looped through to capture the required values as variables. In addition to the obvious ones, like To, From and Subject, we also need to grab the headers References, and In-Reply-To, as they will be needed for sending a reply to this message.<\/span><\/p>\n<p class=\"p1\"><span class=\"s1\">Once the headers are captured, the <em>payload.parts<\/em> array is examined for the email content. If the email has no attachments, then the first part is the plain text version of the body and the second part is the HTML version. The content lives in the path <em>body.data<\/em>\u00a0of each part and is actually encoded as base 64, even though it\u2019s just text. This is what\u2019s known as web safe base 64, which means that any + characters in the base64 are replaced with a \u2013 character and any \/ characters are replaced with the _ character, so before we decode the base64 we need to reverse those substitutions like this:<\/span><\/p>\n<pre class=\"\">Substitute ( [[$b64]] ; [ \"-\" ; \"+\" ] ; [ \"_\" ; \"\/\" ] )<\/pre>\n<h2 class=\"p1\"><span class=\"s1\">Email Attachments<\/span><\/h2>\n<p class=\"p1\"><span class=\"s1\">If the email does have attachments, then the process moves on to the third step of downloading their content. You can step through the script <b>Get Attachment <\/b>to see these processes in more detail.<\/span><\/p>\n<p class=\"p1\"><span class=\"s1\">If the email has attachments, then the first part of the <em>payload.parts<\/em> array will be another array containing the plain text and the HTML. Each subsequent part will represent an attachment. The part will include the headers like the filename and the x-id, which we capture, and the body of the part will be an id representing the attachment content; that will need to come down in another GET request. After looping through all the parts in the array, there will be a list of file names, x-ids and ids for the attachments themselves. The x-ids are captured in case we need to deal with inline attachments. Finally, we loop through the list of attachment ids, and a GET is performed for each one for the content.<\/span><\/p>\n<p class=\"p1\"><span class=\"s1\">The URL for the attachment content is:<\/span><\/p>\n<pre class=\"\">https:\/\/www.googleapis.com\/gmail\/v1\/users\/me\/messages\/[[$messageId]]\/attachments\/[[$attachmentId]]<\/pre>\n<p>And we specify the same cURL options as before:<\/p>\n<pre class=\"\">-H \"Authorization: Bearer [[$accessToken]]\"\n-D \"$responseHeaders\"<\/pre>\n<p>A successful response will be a simple, but large JSON response that looks like this:<\/p>\n<pre class=\"\">{\n  \"data\" : [[b64]],\n  \"size\" : 1000000\n}<\/pre>\n<p class=\"p1\"><span class=\"s1\">This is also web safe base64, so make sure to do the character substitutions mentioned above before decoding it.<\/span><\/p>\n<h2 class=\"p1\"><span class=\"s1\">Inline Email Attachments<\/span><\/h2>\n<p class=\"p1\"><span class=\"s1\">If an inline attachment is received, then the syntax in the HTML will look like this:<\/span><\/p>\n<pre class=\"html\"><img decoding=\"async\" class=\"\" src=\"cid:167b3905c94ee53b3ac1\" alt=\"IMG_0261.JPG\" \/><\/pre>\n<p>This will break when displayed in the web viewer, even though the attachment was retrieved, as it can\u2019t be referenced this way. What we can do to display the image inline is to substitute the \u201ccid:167b3905c94ee53b3ac1\u2033 reference for an inline base64 reference of the image. The cid reference is the x-id that was captured earlier, so a substitute like this can be performed to create the inline base64:<\/p>\n<pre class=\"\">Substitute ( Email::MessageHTML ; \"cid:\" &amp; $attachmentXIds; \"data:image\/png;base64, \" &amp; $b64 )<\/pre>\n<h2 class=\"p1\"><span class=\"s1\">Replying From FileMaker<\/span><\/h2>\n<p class=\"p1\"><span class=\"s1\">Now that we are successfully getting responses to the emails we sent from FileMaker, we want to make sure any additional responses we send are also treated as replies in the same thread. Fortunately, the resumable upload sending method we set up in our last example file doesn\u2019t need to be modified very much to support replies. The main change is in the <b>Request Resumable Upload URL <\/b>script where the parameter for the thread id can now be specified. <\/span><\/p>\n<p class=\"p1\"><span class=\"s1\">If the thread id is not specified then the request is formatted exactly as it was in the last example where we don\u2019t include a body with the POST, and we include the following header:<\/span><\/p>\n<pre class=\"\">-H \"Content-Length: 0\"<\/pre>\n<p class=\"p1\"><span class=\"s1\">If a thread id is specified, then we need to include a simple JSON body with the request specifying the thread id like this. When you include the body the Content-Length header is no longer required.<\/span><\/p>\n<pre class=\"p1\">-d \"{ \"threadId\" : [[$threadId]] }\"<\/pre>\n<p class=\"p1\"><span class=\"s1\">That\u2019s the only change needed in that request. If the thread id is passed, then the resumable upload URL that\u2019s returned \u201cknows\u201d that the forthcoming message belongs to that thread and it doesn\u2019t need to be specified again in the initial and subsequent PUTS to send the message.<\/span><\/p>\n<p class=\"p1\"><span class=\"s1\">The only other change that needs to be made for a reply is that the email headers In-Reply-To and References need to be specified as part of the RFC2822 email form. Those headers are included in the script <b>Create RFC2822 Form<\/b> and pull the values from the fields of the same name in the Email table. Those values were captured when the message was imported into our example file, so they just need to be copied from the incoming message to its reply. This happens in the simple script <b>Reply. <\/b><\/span><\/p>\n<p class=\"p1\"><span class=\"s1\">As mentioned before, both these headers must be specified in the form and the thread id needs to be included in the JSON request for the resumable upload request, or the email won\u2019t be properly threaded. It will send without an error but will come in as a new email to the recipient and not a reply. It seems like a simple change, but I admit it took me a while to figure this out and get it working correctly.<\/span><\/p>\n<h2 class=\"p1\"><span class=\"s1\"><b>Conclusions<\/b><\/span><\/h2>\n<p class=\"p1\"><span class=\"s1\">Although maybe not as flashy as working with HTML and attachments, managing threads is a rich tool to incorporate into your applications. Associating specific threads with specific records in your database keeps your display targeted to just what&#8217;s relevant. By replying correctly from your app, we can ensure these threads aren\u2019t broken and can provide an excellent experience for your FileMaker users and their correspondents.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is the third and final post in a series on using the Gmail API from FileMaker. Please review the previous articles, if you haven\u2019t already, particularly the first one which covers setting your app up with Google and authentication. There\u2019s also a great article by Brendan McBride from dbservices that covers importing emails from an inbox into FileMaker. This article can be seen as the first in the series as it leads directly to the ones we\u2019ve done here. Integrating FileMaker and Gmail Part 1 \u2013 Sending HTML Emails Integrating FileMaker and Gmail Part 2 \u2013 Sending Attachments dbservices \u2013 FileMaker Gmail Integration As with the first article, all of these examples use the native Insert From URL script step so there won\u2019t be any plug-ins required, and since the Insert From URL is supported in all aspects of the FileMaker platform,\u00a0these techniques can be adapted to work\u00a0on the Server, Go, FileMaker Cloud, and WebDirect.\u00a0These techniques require FileMaker 16 or higher as they use the advanced\u00a0cURL options\u00a0introduced in that version. Working With Threads This article will be looking at working with email threads. It will cover querying for responses to a specific thread of emails and maintaining the thread correctly when responding to an email from FileMaker. Here\u2019s a video overview along with a new free example file below: FileMaker Gmail Integration: Example File Please download the example file\u00a0FM2Gmail v1.31\u00a0for a working demo. This new version adds the ability to receive incoming messages for existing threads and reply to them. This file replaces v1.2 from the\u00a0previous article. File updated July 19th, 2019. Managing Replies At the end of our last example, we had successfully sent an HTML email with multiple attachments, but what if the correspondent responds to the message? If we want our outgoing message to be associated with a specific FileMaker record, then it\u2019s likely we\u2019ll want all the responses to this email, and all subsequent responses, to be associated with this record as well. Let\u2019s look at this in action. I\u2019ve sent a message from our example file to myself, and now I\u2019m going to respond and add a new inline attachment to my response.<\/p>\n","protected":false},"author":3,"featured_media":11810,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[33,37],"class_list":["post-11895","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized","tag-filemaker-16","tag-gmail"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Integrating FileMaker and Gmail - Part 3 Email Threads - SeedCode<\/title>\n<meta name=\"description\" content=\"Send and retrieve threaded HTML emails from FileMaker using the Gmail API without plugins. Example file and step-by-step instructions show you how. Techniques work across the whole FileMaker platform including Cloud, Go, and WebDirect.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/seedcode.com\/email-threads-filemaker-gmail\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Integrating FileMaker and Gmail - Part 3 Email Threads - SeedCode\" \/>\n<meta property=\"og:description\" content=\"Send and retrieve threaded HTML emails from FileMaker using the Gmail API without plugins. Example file and step-by-step instructions show you how. Techniques work across the whole FileMaker platform including Cloud, Go, and WebDirect.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/seedcode.com\/email-threads-filemaker-gmail\/\" \/>\n<meta property=\"og:site_name\" content=\"SeedCode\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/seedcoder\" \/>\n<meta property=\"article:published_time\" content=\"2018-12-16T17:09:44+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-02-02T15:24:20+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/seedcode.com\/wp-content\/uploads\/2018\/12\/Gmail3.png\" \/>\n\t<meta property=\"og:image:width\" content=\"319\" \/>\n\t<meta property=\"og:image:height\" content=\"325\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"jasonchryoung\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@dayback\" \/>\n<meta name=\"twitter:site\" content=\"@dayback\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"jasonchryoung\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"11 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/seedcode.com\/email-threads-filemaker-gmail\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/seedcode.com\/email-threads-filemaker-gmail\/\"},\"author\":{\"name\":\"jasonchryoung\",\"@id\":\"https:\/\/seedcode.com\/#\/schema\/person\/21c8e63200786c642eb068377e428ebd\"},\"headline\":\"Integrating FileMaker and Gmail Part 3 \u2013 Email Threads\",\"datePublished\":\"2018-12-16T17:09:44+00:00\",\"dateModified\":\"2023-02-02T15:24:20+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/seedcode.com\/email-threads-filemaker-gmail\/\"},\"wordCount\":2046,\"commentCount\":10,\"publisher\":{\"@id\":\"https:\/\/seedcode.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/seedcode.com\/email-threads-filemaker-gmail\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/seedcode.com\/wp-content\/uploads\/2018\/12\/Gmail3.png\",\"keywords\":[\"FileMaker 16\",\"Gmail\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/seedcode.com\/email-threads-filemaker-gmail\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/seedcode.com\/email-threads-filemaker-gmail\/\",\"url\":\"https:\/\/seedcode.com\/email-threads-filemaker-gmail\/\",\"name\":\"Integrating FileMaker and Gmail - Part 3 Email Threads - SeedCode\",\"isPartOf\":{\"@id\":\"https:\/\/seedcode.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/seedcode.com\/email-threads-filemaker-gmail\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/seedcode.com\/email-threads-filemaker-gmail\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/seedcode.com\/wp-content\/uploads\/2018\/12\/Gmail3.png\",\"datePublished\":\"2018-12-16T17:09:44+00:00\",\"dateModified\":\"2023-02-02T15:24:20+00:00\",\"description\":\"Send and retrieve threaded HTML emails from FileMaker using the Gmail API without plugins. Example file and step-by-step instructions show you how. Techniques work across the whole FileMaker platform including Cloud, Go, and WebDirect.\",\"breadcrumb\":{\"@id\":\"https:\/\/seedcode.com\/email-threads-filemaker-gmail\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/seedcode.com\/email-threads-filemaker-gmail\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/seedcode.com\/email-threads-filemaker-gmail\/#primaryimage\",\"url\":\"https:\/\/seedcode.com\/wp-content\/uploads\/2018\/12\/Gmail3.png\",\"contentUrl\":\"https:\/\/seedcode.com\/wp-content\/uploads\/2018\/12\/Gmail3.png\",\"width\":319,\"height\":325},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/seedcode.com\/email-threads-filemaker-gmail\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/seedcode.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Integrating FileMaker and Gmail Part 3 \u2013 Email Threads\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/seedcode.com\/#website\",\"url\":\"https:\/\/seedcode.com\/\",\"name\":\"SeedCode\",\"description\":\"Build the Software You&#039;ve Always Wanted\",\"publisher\":{\"@id\":\"https:\/\/seedcode.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/seedcode.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/seedcode.com\/#organization\",\"name\":\"SeedCode\",\"url\":\"https:\/\/seedcode.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/seedcode.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/seedcode.com\/wp-content\/uploads\/2022\/12\/SeedCodeLogo.png\",\"contentUrl\":\"https:\/\/seedcode.com\/wp-content\/uploads\/2022\/12\/SeedCodeLogo.png\",\"width\":595,\"height\":189,\"caption\":\"SeedCode\"},\"image\":{\"@id\":\"https:\/\/seedcode.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/seedcoder\",\"https:\/\/x.com\/dayback\",\"https:\/\/www.linkedin.com\/company\/seedcode\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/seedcode.com\/#\/schema\/person\/21c8e63200786c642eb068377e428ebd\",\"name\":\"jasonchryoung\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/seedcode.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/?s=96&d=mm&r=g\",\"caption\":\"jasonchryoung\"},\"url\":\"https:\/\/seedcode.com\/author\/jasonchryoung\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Integrating FileMaker and Gmail - Part 3 Email Threads - SeedCode","description":"Send and retrieve threaded HTML emails from FileMaker using the Gmail API without plugins. Example file and step-by-step instructions show you how. Techniques work across the whole FileMaker platform including Cloud, Go, and WebDirect.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/seedcode.com\/email-threads-filemaker-gmail\/","og_locale":"en_US","og_type":"article","og_title":"Integrating FileMaker and Gmail - Part 3 Email Threads - SeedCode","og_description":"Send and retrieve threaded HTML emails from FileMaker using the Gmail API without plugins. Example file and step-by-step instructions show you how. Techniques work across the whole FileMaker platform including Cloud, Go, and WebDirect.","og_url":"https:\/\/seedcode.com\/email-threads-filemaker-gmail\/","og_site_name":"SeedCode","article_publisher":"https:\/\/www.facebook.com\/seedcoder","article_published_time":"2018-12-16T17:09:44+00:00","article_modified_time":"2023-02-02T15:24:20+00:00","og_image":[{"width":319,"height":325,"url":"https:\/\/seedcode.com\/wp-content\/uploads\/2018\/12\/Gmail3.png","type":"image\/png"}],"author":"jasonchryoung","twitter_card":"summary_large_image","twitter_creator":"@dayback","twitter_site":"@dayback","twitter_misc":{"Written by":"jasonchryoung","Est. reading time":"11 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/seedcode.com\/email-threads-filemaker-gmail\/#article","isPartOf":{"@id":"https:\/\/seedcode.com\/email-threads-filemaker-gmail\/"},"author":{"name":"jasonchryoung","@id":"https:\/\/seedcode.com\/#\/schema\/person\/21c8e63200786c642eb068377e428ebd"},"headline":"Integrating FileMaker and Gmail Part 3 \u2013 Email Threads","datePublished":"2018-12-16T17:09:44+00:00","dateModified":"2023-02-02T15:24:20+00:00","mainEntityOfPage":{"@id":"https:\/\/seedcode.com\/email-threads-filemaker-gmail\/"},"wordCount":2046,"commentCount":10,"publisher":{"@id":"https:\/\/seedcode.com\/#organization"},"image":{"@id":"https:\/\/seedcode.com\/email-threads-filemaker-gmail\/#primaryimage"},"thumbnailUrl":"https:\/\/seedcode.com\/wp-content\/uploads\/2018\/12\/Gmail3.png","keywords":["FileMaker 16","Gmail"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/seedcode.com\/email-threads-filemaker-gmail\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/seedcode.com\/email-threads-filemaker-gmail\/","url":"https:\/\/seedcode.com\/email-threads-filemaker-gmail\/","name":"Integrating FileMaker and Gmail - Part 3 Email Threads - SeedCode","isPartOf":{"@id":"https:\/\/seedcode.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/seedcode.com\/email-threads-filemaker-gmail\/#primaryimage"},"image":{"@id":"https:\/\/seedcode.com\/email-threads-filemaker-gmail\/#primaryimage"},"thumbnailUrl":"https:\/\/seedcode.com\/wp-content\/uploads\/2018\/12\/Gmail3.png","datePublished":"2018-12-16T17:09:44+00:00","dateModified":"2023-02-02T15:24:20+00:00","description":"Send and retrieve threaded HTML emails from FileMaker using the Gmail API without plugins. Example file and step-by-step instructions show you how. Techniques work across the whole FileMaker platform including Cloud, Go, and WebDirect.","breadcrumb":{"@id":"https:\/\/seedcode.com\/email-threads-filemaker-gmail\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/seedcode.com\/email-threads-filemaker-gmail\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/seedcode.com\/email-threads-filemaker-gmail\/#primaryimage","url":"https:\/\/seedcode.com\/wp-content\/uploads\/2018\/12\/Gmail3.png","contentUrl":"https:\/\/seedcode.com\/wp-content\/uploads\/2018\/12\/Gmail3.png","width":319,"height":325},{"@type":"BreadcrumbList","@id":"https:\/\/seedcode.com\/email-threads-filemaker-gmail\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/seedcode.com\/"},{"@type":"ListItem","position":2,"name":"Integrating FileMaker and Gmail Part 3 \u2013 Email Threads"}]},{"@type":"WebSite","@id":"https:\/\/seedcode.com\/#website","url":"https:\/\/seedcode.com\/","name":"SeedCode","description":"Build the Software You&#039;ve Always Wanted","publisher":{"@id":"https:\/\/seedcode.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/seedcode.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/seedcode.com\/#organization","name":"SeedCode","url":"https:\/\/seedcode.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/seedcode.com\/#\/schema\/logo\/image\/","url":"https:\/\/seedcode.com\/wp-content\/uploads\/2022\/12\/SeedCodeLogo.png","contentUrl":"https:\/\/seedcode.com\/wp-content\/uploads\/2022\/12\/SeedCodeLogo.png","width":595,"height":189,"caption":"SeedCode"},"image":{"@id":"https:\/\/seedcode.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/seedcoder","https:\/\/x.com\/dayback","https:\/\/www.linkedin.com\/company\/seedcode\/"]},{"@type":"Person","@id":"https:\/\/seedcode.com\/#\/schema\/person\/21c8e63200786c642eb068377e428ebd","name":"jasonchryoung","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/seedcode.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/?s=96&d=mm&r=g","caption":"jasonchryoung"},"url":"https:\/\/seedcode.com\/author\/jasonchryoung\/"}]}},"_links":{"self":[{"href":"https:\/\/seedcode.com\/wp-json\/wp\/v2\/posts\/11895","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/seedcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/seedcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/seedcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/seedcode.com\/wp-json\/wp\/v2\/comments?post=11895"}],"version-history":[{"count":0,"href":"https:\/\/seedcode.com\/wp-json\/wp\/v2\/posts\/11895\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/seedcode.com\/wp-json\/wp\/v2\/media\/11810"}],"wp:attachment":[{"href":"https:\/\/seedcode.com\/wp-json\/wp\/v2\/media?parent=11895"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/seedcode.com\/wp-json\/wp\/v2\/categories?post=11895"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/seedcode.com\/wp-json\/wp\/v2\/tags?post=11895"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}