Auto-upload email attachments to Google Drive for same-domain recipients

I’m looking for a way to automatically upload file attachments to Google Drive when someone sends emails with attachments to other users within our organization. The idea is that instead of sending the actual file attachment, the system would upload it to Drive and replace the attachment with a sharing link.

The key requirement is that this process should be completely invisible to the person sending the email. They would compose and send emails normally, but recipients would get Drive links instead of direct attachments.

I’m wondering if this functionality can be implemented using the standard Google Drive API methods for uploading files and generating sharing links. Has anyone worked on something similar or can point me in the right direction for the best approach to handle this automatically?

This is totally doable with Google Workspace admin settings plus some custom scripting. I’ve built something similar using Apps Script - it watches for email events and processes attachments before they get delivered. The tricky bit is catching emails at the right moment. You’ll need email routing rules in the admin console to redirect messages through your processing service first. Once you’ve got them, extract the attachments, dump them in a shared Drive folder with the right permissions, then forward the email with Drive links instead of attachments. The sender has no idea this happened. Watch out for large files though - Apps Script has timeout limits, so you might need a queue system for bigger stuff. And make sure your Drive folder setup matches your org’s access policies or you’ll break security.

Implementing this feature with Google Workspace APIs is feasible, but it requires some backend development to process emails effectively. From my experience, establishing a service that utilizes the Gmail API for push notifications can help monitor incoming emails. When an email with attachments is detected, the attachments can be uploaded to a designated Google Drive folder. Subsequently, the original attachments can be replaced with sharing links for the recipients. Ensure that you manage authentication effectively since the service will operate on behalf of users. Additionally, pay careful attention to file permissions to prevent making files publicly accessible, and consider the handling of various file types and sizes to avoid interruptions in the process. The documentation for the Gmail API offers useful guidance on managing attachments.

yeah, totally doable but tricky to implement right. I’d go with webhooks through Gmail API - set up push notifications to a cloud function that catches emails before they’re delivered. when it finds an attachment, upload it to Drive and swap the attachment for a link. the real pain is getting permissions right so people can actually open the files. also watch your storage limits and have a backup plan if the Drive upload craps out - you don’t want emails disappearing into the void.