Download attachments from Gmail using Gmail API

Expanding @Eric answer, I wrote the following corrected version of GetAttachments function from the docs: # based on Python example from # https://developers.google.com/gmail/api/v1/reference/users/messages/attachments/get # which is licensed under Apache 2.0 License import base64 from apiclient import errors def GetAttachments(service, user_id, msg_id): “””Get and store attachment from Message with given id. :param service: Authorized Gmail API … Read more

Bulk-fetching emails in the new Gmail API

Here is an example of batch request in Java where I get all the threads using threads ids. This can be easily adapted for your need. BatchRequest b = service.batch(); //callback function. (Can also define different callbacks for each request, as required) JsonBatchCallback<Thread> bc = new JsonBatchCallback<Thread>() { @Override public void onSuccess(Thread t, HttpHeaders responseHeaders) … Read more

Google Apps Script – Label Email Based On Email Body [Optimize Code]

One method of improving performance in nested loop situations – especially duplicate identification – is to store a record of traversed content, rather than repeatedly comparing. For example, you could hash the message body (given the right hash function) and store the hashes as object properties. Note that there is no formal limit on the … Read more

GmailApp – Add label to specific message, not the thread

You can do this using the GMail API instead. You need to enable the API for your project. In the editor, select Resources > Advanced Google services, then click on “These services must also be enabled in the Google Developers Console.” There, enable the GMail API. modifyMessage Example of use: modifyMessage(‘me’, messageId, [‘stack’,’overflow’]); // add … Read more

Can we access GMAIL API using Service Account?

I use the following C# code for accessing Gmail from Service Account String serviceAccountEmail = “999999999-9nqenknknknpmdvif7onn2kvusnqct2c@developer.gserviceaccount.com”; var certificate = new X509Certificate2( AppDomain.CurrentDomain.BaseDirectory + “certs//fe433c710f4980a8cc3dda83e54cf7c3bb242a46-privatekey.p12”, “notasecret”, X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.Exportable); string userEmail = “[email protected]”; ServiceAccountCredential credential = new ServiceAccountCredential( new ServiceAccountCredential.Initializer(serviceAccountEmail) { User = userEmail, Scopes = new[] { “https://mail.google.com/” } }.FromCertificate(certificate) ); if (credential.RequestAccessTokenAsync(CancellationToken.None).Result) { GmailService … Read more

Retrieving a user’s public google/gmail picture

Is very easy http://picasaweb.google.com/data/entry/api/user/<hereYourUserIdOrYourEmail>?alt=json just has a little problem. You only can get the picture of your Google+ profile, not directly from your gmail. UPDATE: This API is being deprecated and will be turned down in January 2019. Migrate to Google Photos Library API as soon as possible to avoid disruptions to your application. More … Read more