Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I find the definitive attachmentId for an attachment retrieved via Google's Gmail API?

I was under the assumption that each attachment for a given message will have a unique attachmentId that I could use to reference that attachment when needed. Seems this assumption is incorrect.

Each time you call the Users.messages.get service for Google's GMail API ( https://developers.google.com/gmail/api/v1/reference/users/messages/get ) to retrieve a message that has an attachment, the returned attachmentId is different even though the same messageId was used. How would I find the "real" attachmentId?

like image 293
Ben H Avatar asked Jan 23 '15 06:01

Ben H


People also ask

How do I find my Gmail API attachment?

In order to retrieve the the ID of the attachments of a certain message, you would have to get the message resource via Users. messages. get, and from that response, retrieve the ID of the attachment.

Where are attachments settings in Gmail?

Steps to Configure Attachment Compliance in GmailScroll down to find Gmail and click on it. Scroll down to Advanced settings and click on it. Scroll down to Attachment compliance and hover on it and to see configure option and click on it. Select the messages that you want to affect.

How can I read Gmail with Gmail API in PHP?

php'; $client = new Google_Client(); $client->setClientId($this->config->item('gmailapi_clientid')); $client->setClientSecret($this->config->item('gmailapi_clientsecret')); $client->setRedirectUri(base_url('auth')); $client->addScope('email'); //$client->addScope('profile'); $client->addScope('https://mail.google.com' ...


1 Answers

I have myself had to store attachment ids in database, and I am not even yet sure if both of my options below are indeed persistent. My tests over several weeks while working on it seems to suggest it however, but I cannot guarantee it.

  1. Use a key based on threadid, messageid and partid for the attachment.

  2. Take a look at the MessagePartHeader for an 'X-Attachment-Id' value. These id's is what I currently use for storing attachment ids.

like image 161
Geir Thomas Jakobsen Avatar answered Nov 09 '22 00:11

Geir Thomas Jakobsen