Get email count of search results in Gmail API - gmail-api

I am implementing email functionality using PHP using Google API PHP SDK and I want to get total count of emails for search result.
I managed to get email count of inbox, sent mails, specific labels etc. but there is no option to count total number of emails in the search result.
Please help me.
Thanks.

Related

Query Gmail by internalDate in API?

I am attempting to use the Gmail API to download all the messages inside of an account. I would like to be able to allow this process to pick up where it left off in the event that it stops or has to be run again in order to find newer messages.
At first glance it looks like what I need to do is keep track of the internalDate on the messages that I am retrieving and then use that in the q variable when I call the users.messages.list endpoint. However, I am having trouble finding a way to use that when I query the API.
Does anyone know of a way to query Gmail for all messages that have an internalDate greater or less than a specific value? Or is there a better way to download all messages inside of a Gmail account?

How to get all unique email recipients python gmail api

I want to do a search for all unique email recipients from gmail. But I'm really struggling with API. If I was interacting with a SQL database I would want something like:
SELECT DISTINCT EmailRecipient FROM MyHypotheticalGmailTable;
But I'm not sure how to translate this into a gmail API call.
I suggest you start by taking a look at the Gmail API Quickstart with Python here.
Afterwards you may want to take a look at threads.list in order to list all the threads available and then for each one use threads.get. Since there is no direct method of retrieving the unique email recipients, you will have to handle this separately from the API calls and filter the results programmatically.
Reference
Gmail API Python Quickstart;
Gmail API messages.list;
Gmail API messages.get.

Is there a way to run email to/from search via the Google Email API?

I haven't been able to find any information on an API that allows to perform an email API log search on G-Suite. For security, we want to be able to have to run a search for, say, all emails originating from user#ourgsuitedomain.com and all emails coming to. While this is possible in admin.google.com, I want to know if it's possible via an API.
All I found about this is outdated threads right here on SO.
The only option to audit emails is to create an email monitor with the Email Audit API, in the case that you may want to implement ver singular search criteria, consider that the API may not fit your requirements completely. You can find the documentation at https://developers.google.com/admin-sdk/email-audit/

Fetch gmail thread conversation of my crm contacts only

Basically am using gmail php api to show gmail inbox for my users. But the main thing is that i only want to show the gmail thread conversations of my crm contacts. For this i pass all the emails of my contacts in the q parameter of gmails threads but this the q parameter works only untill 250 emails after that i got bad request error in response. could anyone please tell is there any limit on the length of q parameter of gmail php api or a better way to handle this situation..
Because of the query length limit, you will most likely have to divide your set of emails into batches that fit within the query limit.
If performance is an issue, you can use a batch request to group the email batches into a single request. See: https://developers.google.com/gmail/api/guides/batch
Note: the requests within your batch will still be subject to rate and concurrent request limits. See: https://developers.google.com/gmail/api/v1/reference/quota

Sender ID record when sending email with GAE

My GAE app sends email, and I followed Jeff Atwood's excellent article to improve the likelihood of email delivery.
The first two steps are really easy, but setting up a Sender ID record is more challenging. The article provides a link to a "Wizard" to help do this, but I don't know the answer to many of the questions in the wizard.
I use Google Apps for email so I'm thinking the Sender ID record should be the same for many other people in my situation (Google Apps and GAE users).
Can anyone point me to a Sender ID record for this?
EDIT:
This page explains how to set the SPF and SenderID record for Amazon SES, and gives the following TXT record for SPF:
v=spf1 include:amazonses.com -all
and the following TXT record for SenderID:
spf2.0/pra include:amazonses.com -all
Leontx's answer appears to give an SPF record and not a SenderID record.
Also, when I look at the headers of the email I send with GAE, there are notes saying that SPF authentication passes even though I haven't added either of the above TXT records to my domain. There is no info in the headers about SenderID.
I'm still confused about this, but I will now be using Amazon SES to send email. It is really cheap and it seems that Amazon takes a lot more care than Google to help make sure that email gets delivered.
Here's the TXT record I had to create to get SenderID to pass:
Host: #
Text value: v=spf1 include:_spf.google.com ~all
But I had to get both SenderID and DKIM passing to get mail into Hotmail's inbox. To get DKIM to pass I had to create a custom domain for our GAE app that matched the domain of the email's From address. Then I had enable DKIM through that domain's Google Apps account. Then it finally worked.
GAE mail (I use Python) does not give any feedback when you send mail. To receive feedback you have to use another service /API. I use Amazon SES in my applications.

Resources