I am working on a gmail app (you can probably tell if you read my other questions), I can list my first 10 email, however I have no way of knowing weather they are read or not. Does anyone know how I would even go about this? Thanks!
To find out when an email you sent was opened, you can request a read receipt. A read receipt is sent to you as an email with the time and date of when your message was opened. Want to get more out of Google apps at work or school? Sign up for a Google Workspace trial at no charge.
Request a return receipt Most major email platforms will give you the option to request return/read receipts with email that you send. Some will also let you specify these receipts for every email you're composing.
If I list my newest message:
GET https://www.googleapis.com/gmail/v1/users/me/messages?maxResults=1&access_token={ACCESS_TOKEN}
{
"messages": [
{
"id": "158d822014b7887b",
"threadId": "158d822014b7887b"
}
],
"nextPageToken": "17683191771541399341",
"resultSizeEstimate": 2
}
And then get the message:
GET https://www.googleapis.com/gmail/v1/users/me/messages/158d822014b7887b?format=metadata&access_token={ACCESS_TOKEN}
{
"id": "158d822014b7887b",
"threadId": "158d822014b7887b",
"labelIds": [
"UNREAD",
"CATEGORY_SOCIAL",
"INBOX"
],
...
}
You can see that the message has a labelId
with the value of UNREAD
. If the message doesn't have this labelId
, it is read.
var isRead = message.labelIds.indexOf("UNREAD") === -1;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With