{"id":1942,"date":"2011-08-30T11:10:07","date_gmt":"2011-08-30T09:10:07","guid":{"rendered":"http:\/\/www.limilabs.com\/blog\/?p=1942"},"modified":"2022-03-30T15:02:47","modified_gmt":"2022-03-30T13:02:47","slug":"create-gmail-url-id-via-imap","status":"publish","type":"post","link":"https:\/\/www.limilabs.com\/blog\/create-gmail-url-id-via-imap","title":{"rendered":"Create Gmail url-ID via IMAP"},"content":{"rendered":"<p>This is Gmail link that points to certain conversation (entire thread):<\/p>\n<p><code>https:\/\/mail.google.com\/mail\/u\/0\/#inbox\/13216515baefe747<\/code><\/p>\n<p>&#8220;13216515baefe747&#8221; is the Gmail thread-ID in hex.<\/p>\n<p>Here&#8217;s the code that:<\/p>\n<ol>\n<li>Selects &#8220;All Mail&#8221; folder<\/li>\n<li>Gets the newest message UID<\/li>\n<li>Obtains Gmail thread ID for this message (X-GM-THRID)<\/li>\n<li>Converts it to hex<\/li>\n<li>Creates the url that points to the Gmail conversation<\/li>\n<\/ol>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\n\/\/ C# version\n \nusing (Imap client = new Imap())\n{\n    client.ConnectSSL(\"imap.gmail.com\");\n    client.UseBestLogin(\"pat@gmail.com\", \"app-password\");\n \n    \/\/ Select 'All Mail' folder\n    CommonFolders common = new CommonFolders(\n        client.GetFolders());\n    client.Select(common.AllMail);\n \n    \/\/ get IMAP uid of the newest message\n    long lastUid = client.GetAll().Last();\n \n    \/\/ get message info\n    MessageInfo info = client.GetMessageInfoByUID(lastUid);\n \n    \/\/ extract Gmail thread ID\n    decimal threadId = info.Envelope.GmailThreadId;\n    string threadIdAsHex = threadId.ToString(\"x\");\n \n    \/\/ create url\n    string url = string.Format(\n        \"https:\/\/mail.google.com\/mail\/u\/0\/#inbox\/{0}\",\n        threadIdAsHex);\n \n    Console.WriteLine(url);\n \n    client.Close();\n}\n<\/pre><\/div>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: vb; title: ; notranslate\" title=\"\">\n' VB.NET version\n \nUsing client As New Imap()\n    client.ConnectSSL(\"imap.gmail.com\")\n    client.UseBestLogin(\"pat@gmail.com\", \"app-password\")\n \n    ' Select 'All Mail' folder\n    Dim common As New CommonFolders(client.GetFolders())\n    client.Select(common.AllMail)\n \n    ' get IMAP uid of the newest message\n    Dim lastUid As Long = client.GetAll().Last()\n \n    ' get message info\n    Dim info As MessageInfo = client.GetMessageInfoByUID(lastUid)\n \n    ' extract Gmail thread ID\n    Dim threadId As Decimal = info.Envelope.GmailThreadId\n    Dim threadIdAsHex As String = threadId.ToString(\"x\")\n \n    ' create url\n    Dim url As String = String.Format( _\n        \"https:\/\/mail.google.com\/mail\/u\/0\/#inbox\/{0}\", _\n        threadIdAsHex)\n \n    Console.WriteLine(url)\n \n    client.Close()\nEnd Using\n<\/pre><\/div>\n\n\n<p>Here you can find some more information about how to <a href=\"\/blog\/search-gmail-thread-id\">search by X-GM-THRID<\/a> and all other <a href=\"\/blog\/gmail-extensions-in-mail-dll\">Gmail IMAP extensions<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is Gmail link that points to certain conversation (entire thread): https:\/\/mail.google.com\/mail\/u\/0\/#inbox\/13216515baefe747 &#8220;13216515baefe747&#8221; is the Gmail thread-ID in hex. Here&#8217;s the code that: Selects &#8220;All Mail&#8221; folder Gets the newest message UID Obtains Gmail thread ID for this message (X-GM-THRID) Converts it to hex Creates the url that points to the Gmail conversation Here you [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[15,25,28,77,57,66],"class_list":["post-1942","post","type-post","status-publish","format-standard","hentry","category-mail-dll","tag-c","tag-gmail","tag-imap","tag-imap-component","tag-vb-net","tag-x-gm-thrid"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/1942"}],"collection":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/comments?post=1942"}],"version-history":[{"count":14,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/1942\/revisions"}],"predecessor-version":[{"id":6095,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/1942\/revisions\/6095"}],"wp:attachment":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/media?parent=1942"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/categories?post=1942"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/tags?post=1942"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}