{"id":8665,"date":"2025-03-17T02:27:21","date_gmt":"2025-03-17T02:27:21","guid":{"rendered":"https:\/\/pariswells.com\/blog\/?p=8665"},"modified":"2025-03-27T10:12:47","modified_gmt":"2025-03-27T10:12:47","slug":"cannot-forward-emails-to-receiptsexpensify-com-from-gmail-as-cannot-verify-the-email-address","status":"publish","type":"post","link":"https:\/\/pariswells.com\/blog\/research\/cannot-forward-emails-to-receiptsexpensify-com-from-gmail-as-cannot-verify-the-email-address","title":{"rendered":"Cannot forward emails to receipts@expensify.com from Gmail as cannot verify the email address"},"content":{"rendered":"\n<p>In gmail you have to verify the email address before you can forward emails to it. The verification code comes in the body of the email not as an attachment so expensify rejects it \ud83d\ude41  <\/p>\n\n\n\n<p>You can use a Script in Gmail to forward emails <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">\/\/ Forwards all emails in the inbox from `from_email` to Expensify, and archive them.\n\/\/\n\/\/ To use:\n\/\/ Add this function to a Google Apps Scripts project, and add a trigger (in Resources -> Current Project Triggers)\n\/\/ to call it on a given interval. \n\/\/ Make sure to specify the senders you'd like to forward!\n\n\nfunction toExpensifyBySender() {\n  var fromEmails = [\n    \"transaction@notice.aliexpress.com\"\n  ];\n  \n  fromEmails.forEach(function(email) {\n    var threads = GmailApp.search('from:' + email + ' in:inbox');\n    threads.forEach(function(thread) {\n      thread.getMessages().forEach(function(message) {\n        message.forward('receipts@expensify.com');\n      });\n      thread.moveToArchive();\n    });\n  });\n}\n\nfunction toExpensifyBySender() {\n  var fromEmails = [\n    \"service@paypal.co.uk\"\n  ];\n  \n  \/\/ Subject terms with wildcards\n  var subjectTerms = [\n    \"receipt for your payment to aliexp*\"\n  ];\n  \n  \/\/ Convert to regex patterns with simpler approach\n  var termPatterns = subjectTerms.map(term => {\n    \/\/ Replace * with .* and ensure proper escaping\n    const patternStr = term.replace('*', '.*');\n    const regex = new RegExp(patternStr, 'i');\n    Logger.log('Created pattern: ' + regex);\n    return regex;\n  });\n  \n  try {\n    fromEmails.forEach(function(email) {\n      var searchQuery = 'from:' + email + ' in:inbox';\n      Logger.log('Search query: ' + searchQuery);\n      var threads = GmailApp.search(searchQuery);\n      \n      Logger.log('Found ' + threads.length + ' threads');\n      if (threads.length === 0) {\n        Logger.log('No threads found for ' + email);\n        return;\n      }\n      \n      threads.forEach(function(thread, threadIndex) {\n        Logger.log('Processing thread ' + threadIndex);\n        var messages = thread.getMessages();\n        var hasMatchingMessage = false;\n        \n        messages.forEach(function(message, msgIndex) {\n          var subject = message.getSubject().toLowerCase();\n          Logger.log('Thread ' + threadIndex + ', Message ' + msgIndex + ' subject: \"' + subject + '\"');\n          \n          \/\/ Test each pattern explicitly\n          var matchedPattern = termPatterns.find(pattern => {\n            const matches = pattern.test(subject);\n            Logger.log('Testing pattern ' + pattern + ' against \"' + subject + '\": ' + matches);\n            return matches;\n          });\n          \n          if (matchedPattern) {\n            if (!message.isInTrash() &amp;&amp; !message.isDraft()) {\n              Logger.log('Matched pattern: ' + matchedPattern + ' - Forwarding message');\n              message.forward('receipts@expensify.com', {\n                name: 'Expense Bot',\n                noReply: true\n              });\n              hasMatchingMessage = true;\n            } else {\n              Logger.log('Message skipped (in trash or draft)');\n            }\n          } else {\n            Logger.log('No pattern matched for this subject');\n          }\n        });\n        \n        if (hasMatchingMessage) {\n          Logger.log('Archiving thread ' + threadIndex);\n          thread.moveToArchive();\n        } else {\n          Logger.log('Thread ' + threadIndex + ' had no matching messages');\n        }\n      });\n    });\n  } catch (error) {\n    Logger.log('Error occurred: ' + error.toString());\n  }\n}<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/pariswells.com\/blog\/wp-content\/uploads\/2025\/03\/image-6.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"352\" src=\"https:\/\/pariswells.com\/blog\/wp-content\/uploads\/2025\/03\/image-6-1024x352.png\" alt=\"\" class=\"wp-image-8666 img-responsive\" srcset=\"https:\/\/pariswells.com\/blog\/wp-content\/uploads\/2025\/03\/image-6-1024x352.png 1024w, https:\/\/pariswells.com\/blog\/wp-content\/uploads\/2025\/03\/image-6-300x103.png 300w, https:\/\/pariswells.com\/blog\/wp-content\/uploads\/2025\/03\/image-6-768x264.png 768w, https:\/\/pariswells.com\/blog\/wp-content\/uploads\/2025\/03\/image-6-1536x529.png 1536w, https:\/\/pariswells.com\/blog\/wp-content\/uploads\/2025\/03\/image-6.png 1633w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/pariswells.com\/blog\/wp-content\/uploads\/2025\/03\/image-7.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"188\" src=\"https:\/\/pariswells.com\/blog\/wp-content\/uploads\/2025\/03\/image-7-1024x188.png\" alt=\"\" class=\"wp-image-8667 img-responsive\" srcset=\"https:\/\/pariswells.com\/blog\/wp-content\/uploads\/2025\/03\/image-7-1024x188.png 1024w, https:\/\/pariswells.com\/blog\/wp-content\/uploads\/2025\/03\/image-7-300x55.png 300w, https:\/\/pariswells.com\/blog\/wp-content\/uploads\/2025\/03\/image-7-768x141.png 768w, https:\/\/pariswells.com\/blog\/wp-content\/uploads\/2025\/03\/image-7-1536x282.png 1536w, https:\/\/pariswells.com\/blog\/wp-content\/uploads\/2025\/03\/image-7.png 1862w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>In gmail you have to verify the email address before you can forward emails to it. The verification code comes in the body of the email not [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-8665","post","type-post","status-publish","format-standard","hentry","category-research"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/posts\/8665","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/comments?post=8665"}],"version-history":[{"count":2,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/posts\/8665\/revisions"}],"predecessor-version":[{"id":8683,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/posts\/8665\/revisions\/8683"}],"wp:attachment":[{"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/media?parent=8665"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/categories?post=8665"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/tags?post=8665"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}