Is there a way to automatically delete emails from a Google Workspace Google Groups? - google-apps-script

I was wondering if there is a way to automatically (or on a trigger) delete emails from a Google Group.
I use a Collaborative Inbox Group for archiving automated emails.
I looked at the Google Apps Script overview for Google Groups, but I don't see anything. It only seems like you can do this from GmailApp...
I also read this thread from 2012 but nothing helpful there

Answer:
Programmatically this isn't possible.
More Information:
The GroupsApp class of Apps Script only has read methods available for use - there is not a way of executing any write data using the class - for example deletion of emails.
Emails are sent to everyone in the group when a post is made (as per subscription settings). If you want the Email to be deleted then as you have already pointed out, you will need to use GmailApp to delete it from the recipients' inboxes.
In short: All mailbox manipulation must be done using the Gmail API (or GmailApp).
Feature Request:
You can however let Google know that this is a feature that is important for access to their APIs, and that you would like to request they implement it.
Google's Issue Tracker is a place for developers to report issues and make feature requests for their development services, I'd urge you to make a feature request there. The best component to file this under would be the Admin SDK component, with the Feature Request template.

Related

Can email be deleted from your users' Gmail inboxes programmatically via API?

The "Find and delete malicious emails" page in the Google Workspace Admin Help Center states:
Using the investigation tool, you can identify all users in your domain that have received the message (for example, a phishing email). You can then use the investigation tool to delete the email from your users' Gmail inboxes (note that log data might take up to a few minutes before being available in the investigation tool).
From this, I understand that, assuming you have the right package, it is possible to use the investigation tool to delete the unwanted email from your users' Gmail inboxes.
Can I delete emails from my users' Gmail inboxes via Google App Script using the API? If so, how can I do that?
Currently it is not possible with the Investigation tool
But there is already an existing feature request for exposing the Google Workspace Investigation Tool programmatically.
I recommend you to "star" it to show Google that more people are interested in this feature - hopefully this will accelerate the implementation.
UPDATE:
In th meantime you can use a workaround, e.g. using a service account with domain-wide delegation as suggested by #TheAddonDepot
It is possible via DwDg(domain-wide delegation)
You have to create a service account and delegate domain-wide authority to that service account with the appropriate scopes. There are no explicit instructions for the Gmail API but you can use this guide from the Admin Directory API documentation.
You then use the service account credentials with the GAS OAuth2 Library to make calls on behalf of your existing users to the Gmail API. Note that you can't use the built-in or advanced services for Gmail, you'll have to call out to the Gmail REST API directly via UrlFetchApp.

How to select account in Google App Scripts for users with multiple accounts?

For users that are logged into multiple accounts, how can a script let the user pick an account? For example, Gmail, Google Drive, etc. provide a way for the user to select which account to use with a selectable option on the top-right of the page:
How can developers implement a similar mechanism?
There seems to be no way to do that with Google Apps Script libraries - GAS just uses the current primary account. Also, unfortunately, the API Client Library and thus Google Sign-In for websites don't work inside GAS web apps because of the sandbox frame. You could write your own or use some existing OAuth implementation to authenticate with Google but I found a much much simpler solution using Auth0 Lock with only a Google Connection (using the popup method because the redirect method doesn't work within the sandbox frame).
With Chrome Version 70.0.3538.102. You may resolve your issue (at least i did)
Now i make sure i ONLY signed in ONE account at a time. Then use "manage people"
if i have 3 google accounts, i will create 3 people and each time you only have 1 active google account session. With this setup, i ensured everytime my script only execute with my G Suite user instead of #gmail accounts
You can try using the Directory API to work with Apps Script. Retrieve the user using:
GET https://www.googleapis.com/admin/directory/v1/users/userKey.
You can then make an interface that displays the user accounts details(Name, email,etc).

How to use the calDAV protocol on a Flex application?

I'm a trainee and am learning about Flex, so I'm a total noob at this... My boss asked me to research the calDAV protocol for us to use in a calendar app we already have. I was trying to understand the Google API but I have no clue how to put this in our code. He wants me to make it possible to share events added to our calendar in Google Calendar or IPhone, for example. I'm starting to get desperate :(
It appears as the Google CalDAV API is deprecated and it will likely go offline at some point soon.
Edit: The Google CalDAV API is not being deprecated, only the previous endpoint. Wording below has been amended to recommend Google's own API as an alternative method.
CalDAV itself is basically just a way to format information about calendar events in a specific way for communicating between services. It also defines how to send and receive this information. Here's the CalDAV specification for more info.
If the requirement is to work with Google Calendar but not specifically with CalDAV, you could look at v3 of their API. It appears to be based more around JSON which should make it slightly easier to work with in AS3. There appears to be AS3 libraries out there for Google Calendar, but they seem to be outdated and unsupported, so it's likely that they won't work with the latest versions of the API.
The Google API relies on REST calls. It basically means that you send HTTP GET, POST, DELETE etc requests to specified URLs on Google's servers to do specific tasks or to request data.
In order to use the API you need to authorize your requests. The most common way to do this is to use OAuth 2.0 - in which your user grants your application access to its Google account, and in turn your application receives a token that needs to be sent with each request.
This isn't a complete answer to your problem, but I hope it outlines the process and gives you some useful links to read.

Apps Script HTML Service Post request / sheet append limits

We have a chrome extension that posts data back to a Google Apps Script app and I'd like to know if I'm going to hit any limits at Google.
The Apps Script app has a doPost function that takes the information that was passed across and uses appendRow to add the content to different sheets. Very similar to how forms works but allows us to deploy to users (via the chrome extension) and have a better looking UI.
We're wanting to push this out to potentially thousands of users and we expect a few form submissions a day from each of them. Should I be expecting to hit any set limits with this?
I've already taken a look at https://script.google.com/a/netpremacy.com/dashboard but don't see anything that would indicate any limits.
Let me know if you need more info.
There are no published limits at this time. However, the key thing to ask with apps deployed as web apps is that is the App running as you (the developer) OR the users accessing the web app?
If its running as the users, then you are going to be ok with the volume. The quota is fully debited to the end user.
If its running as you, then you need to worry about other quota first - does it send out lots of emails, does it create a lot of documents, etc.
The only exception to quotas is ScritptDb that always consumes the script developers quota.

“Pushing” Gmail to GAS — using Gmail forwarding to trigger GAS script

Summary
Is it possible to use the Gmail forwarding feature to send (i.e., “push”) via HTTP (GET/POST) to my GAS script URL? (And perhaps include its contents as a parameter?)
Goal/Background
My goal is to immediately process my incoming Gmail instead of, say, using the GAS trigger feature to query and “pull” my Gmail on a periodic basis.
The former method is relatively immediate. Whereas, the latter method creates an expected delay equal to the mean interval time between (automatically triggered) queries to my inbox.
Possible Solutions
1. Gmail Data API
This documentation states Gmail lacks a data API.
2. Atom/RSS Feeds
Atom/RSS feeds still require an aggregator to pull the data from the server and, thus, do not accomplish my goal of a push-only solution to my GAS URL to, then, in turn, trigger my script via doGet() or doPost().
3. IMAP/POP
These solutions are designed for desktop/offline processing of emails and, therefore, do not meet my goals. I need a solution that lives on the web and automates my web-based email checking tasks.
4. High-frequency GAS Trigger
A, say, 60-second trigger interval in GAS does not work because there is a cost to such high-frequency triggers in GAS due to quota limitations. i.e., I don't want to use up that much quota space on this one task because I need it for other stuff.
5. 3rd Party Listeners
I would prefer something free if possible. Someone has suggested Zapier® — which does have a free version. Do these work? Are there others?
Conclusion
Are there any creative ideas out there? Perhaps to point me in a creative direction?
I would even settle for just a way to be immediately notified (programmatically) that I received a new email.
Not possible from Google Apps Script:
Google Apps Script currently available events:
https://developers.google.com/apps-script/understanding_events
Does Gmail have a Data API?
FAQ: https://developers.google.com/gdata/faq#GmailAtomFeed
Looks like IMAP is the only option, not sure if IMAP supports callback.
A trigger can kick off a script every 60 seconds. As you stated before, this puts your average notification at 30 seconds (let's not get started on possible flaws in statistical assumptions).
Another possibility for a more immediate action is to use a service like Zapier.com as a listener. It can listen for new emails in your gmail inbox, apply filters, and initiate a GET/POST to the URL for your Apps Script (make sure it is the newest version published).
I hope this helps. Curious why you need immediate handling of the messages ...