I’m working on a project where I want to automatically upload file attachments to Google Drive when someone sends emails with attachments to colleagues within our organization. The idea is that instead of sending the actual file attachment, the system would upload it to Drive and include the sharing link in the email instead.
This should work completely behind the scenes so the person sending the email doesn’t need to do anything different. They would compose their email normally with attachments, but the system would handle the Drive upload automatically.
I’m wondering if this can be accomplished using the standard Google Drive API methods for uploading files and managing permissions. Has anyone implemented something similar before? What would be the best approach to make this seamless for users?
I built something like this for our company two years ago. The Drive API integration was straightforward - the real challenge was intercepting emails at the right moment. We used Google Apps Script with Gmail API triggers to catch outgoing emails before they sent, then pushed attachments through the Drive API. You’ll need workspace-wide permissions so the script can access user emails and create shared Drive folders. Performance was a pain with bigger files since uploads had to finish before emails could send. We added a queue for anything over 10MB. Some users actually want attachments in their email for offline access, so we made it optional per user. The Drive API handles this fine, but be careful with email interception - your IT team will have security concerns.
We did this exact setup six months ago with Gmail Push API and Drive API. The trick is setting up workspace delegation so your service account can handle uploads without any user input. Don’t delay email sending - process everything server-side through Pub/Sub notifications. When an email with attachments hits our internal domain, the system creates a shared Drive folder, uploads the files, sets permissions for the recipient, and swaps attachment references with Drive links in the email. Watch out for file naming conflicts and make sure the original sender gets edit permissions on uploaded files. Also check your Drive storage quotas can handle the volume - we totally underestimated how much space this eats up.
definitely doable but watch out for timeouts. Gmail API limits how long you can delay sending while uploading to Drive. We hit issues where big files made emails fail completely. switched to webhooks instead - emails send normally first, then our script handles attachments async and sends follow-ups with Drive links. less seamless but way more reliable than intercepting everything upfront.