tjpoe
tjpoe

Reputation: 11

Is there a place to get more granular reporting data via API?

I'm trying to figure out a way to export some of the events I can see in the security dashboard and alert center. The Customer Reports API only gives me the # of mail received per day, and # or spam messages per day, but is more than 24 hrs behind.

I've tried to create an alert in the security alerts center for whenever my domain gets a relevant email, but I just get an email once a minute that says the the threshold was exceeded, and I have to click into the investigation tool to actually get the relevant data.

Is there a place I can request # of phishing emails per hour, or be alerted whenever new phishing emails are found. Or Malware, etc.

Upvotes: 0

Views: 81

Answers (1)

ziganotschka
ziganotschka

Reputation: 26836

  • The Reports API method UserUsageReport: get allows you to retrieve received spam emails for a certain date by specifying the parameter gmail:num_spam_emails_received
  • However, if you want to retrieve e.g. the emails from the last hour, there is no prebuilt functionality for this.

You can write a Google Apps Script that would browse your Gmail Inbox for new Spam Emails and set the script on a time-driven trigger

Sample:

function setmeOnHourlyTimer() {
  var now = new Date();
  var oneHourAgoinSeconds = Math.round(now.getTime()/1000 - 1200 *60);
  var query = '"after:'+ oneHourAgoinSeconds  +'"';
  var spamMessages = Gmail.Users.Messages.list("YOU_EMAIL", {"labelIds": ["SPAM"] , "q": query}).messages;
  if (spamMessages.length > 0){
    GmailApp.sendEmail("paste your email here", "You have new Spam emails", "You got " + spamMessages.length + " new spam message(s) within the last hour.")
  }
}


Upvotes: 0

Related Questions