Google Apps Script: GmailApp Not Returning Emails with after/before Query

In Google Apps Script, you cannot just use after and before keyword in query. You’ll need the date to be converted to Epoch (seconds) first. Not even ISO 8601.

i.e Query to get GitHub Invocies for username chez14:

// Wrong:
from:[email protected] subject:"payment receipt" chez14 after:2024-08-04T15:10:40+07:00

// Correct:
from:[email protected] subject:"payment receipt" chez14 after:1722759040

On the UI, you can do that and the result may still come up, but in APIs, you have to provide Epoch.


Thanks to this comment:

  • https://stackoverflow.com/questions/45029728/gmailapp-search-seems-to-fail-correct-data#comment77059962_45033558

Disclaimer:

Not all articles here are meant to be correct. My notes might be wrong or may no longer be relevant. If you want to try things here, please proceed with caution.


Posted

in

by

Tags: