Gmail to S3 Attachment Workflow

Complete System Design & Implementation Guide

Paragon Dashboard Integration

Generated:

Table of Contents

System Architecture Overview

Gmail Trigger
Email Processing
Attachment Extraction
S3 Upload
Notification/Logging

Key Benefits

Phase 1: Environment Setup & Prerequisites

1.1 Gmail Integration Setup

Step 1.1.1: Configure Google Cloud Console

  1. Go to Google Cloud Console
  2. Create new project or select existing project
  3. Navigate to "APIs & Services" → "Library"
  4. Search and enable "Gmail API"

Step 1.1.2: Create OAuth Credentials

  1. Go to "APIs & Services" → "Credentials"
  2. Click "+ Create Credentials" → "OAuth client ID"
  3. Select "Web application"
  4. Add authorized redirect URI: https://passport.useparagon.com/oauth
  5. Save Client ID and Client Secret

Step 1.1.3: Configure in Paragon Dashboard

  1. Open Paragon Dashboard → "Integrations" → "Gmail"
  2. Under "App Configuration", click "Configure"
  3. Enter Client ID and Client Secret from Step 1.1.2
  4. Select required scopes:
    • https://www.googleapis.com/auth/gmail.readonly
    • https://www.googleapis.com/auth/gmail.compose
  5. Save changes

1.2 Amazon S3 Integration Setup

Step 1.2.1: AWS IAM Configuration

  1. Create IAM user with programmatic access
  2. Attach policy with S3 permissions:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "s3:PutObject", "s3:GetObject", "s3:DeleteObject" ], "Resource": "arn:aws:s3:::your-bucket-name/*" } ] }

Step 1.2.2: Configure S3 in Paragon

  1. Paragon Dashboard → "Integrations" → "Amazon S3"
  2. Enter AWS Access Key ID and Secret Access Key
  3. Test connection and save

1.3 Recommended S3 Bucket Structure

your-bucket/ ├── gmail-attachments/ │ ├── 2025/ │ │ ├── 01/ │ │ │ ├── 01/ │ │ │ │ ├── email-{timestamp}-{sender}/ │ │ │ │ │ ├── attachment1.pdf │ │ │ │ │ └── attachment2.docx

Phase 2: Workflow Design & Architecture

2.1 Workflow Components Architecture

Detailed Flow:

Gmail Trigger
Email Validation


Attachment Check
Email Metadata Extraction


Attachment Processing Loop
File Type Validation


S3 Path Generation
S3 Upload


Upload Verification
Logging/Notification

2.2 Data Flow Design

Input Data Structure:

{ "email": { "id": "email_id", "threadId": "thread_id", "sender": "sender@example.com", "subject": "Email Subject", "date": "2025-01-01T10:00:00Z", "attachments": [ { "filename": "document.pdf", "mimeType": "application/pdf", "size": 1024000, "attachmentId": "attachment_id" } ] } }

Phase 3: Detailed Workflow Implementation

3.1 Create New Workflow

Step 3.1.1: Initialize Workflow

  1. Paragon Dashboard → "Workflows" → "Create New Workflow"
  2. Name: "Gmail Attachments to S3 Processor"
  3. Description: "Automatically processes Gmail attachments and uploads to S3"

3.2 Configure Gmail Trigger

Step 3.2.1: Add Trigger Step

  1. Click "Add Trigger" → Select "Gmail"
  2. Choose trigger type: "New Email" or "New Thread"
  3. Configure trigger settings:
    • Label Filter: (Optional) Specific Gmail label
    • Query Filter: has:attachment to only trigger on emails with attachments
    • Sender Filter: (Optional) Specific sender domains

Step 3.2.2: Test Trigger

  1. Click "Test Trigger" button
  2. Send test email with attachment to connected Gmail account
  3. Verify trigger captures email data correctly

3.3 Email Processing Steps

Step 3.3.1: Add Email Validation Step

  1. Add "Function" step after trigger
  2. Name: "Validate Email Data"
  3. JavaScript code:
function main(trigger) { const email = trigger.email; // Validate required fields if (!email.id || !email.attachments || email.attachments.length === 0) { throw new Error('Invalid email data or no attachments found'); } // Filter out inline images and unwanted file types const validAttachments = email.attachments.filter(att => { const isInline = att.disposition === 'inline'; const isImage = att.mimeType.startsWith('image/'); const isValidSize = att.size > 0 && att.size < 26214400; // 25MB limit return !isInline && isValidSize; }); return { email: email, processableAttachments: validAttachments, metadata: { sender: email.from, subject: email.subject.replace(/[^\w\s-]/g, ''), // Clean subject for folder naming timestamp: new Date().toISOString(), totalAttachments: validAttachments.length } }; }

Step 3.3.2: Add Attachment Extraction Step

  1. Add "Gmail" integration step
  2. Action: "Get Attachment"
  3. Configure:
    • Message ID: {{trigger.email.id}}
    • Attachment ID: {{validation.processableAttachments[0].attachmentId}}
  4. Enable "Continue workflow if step fails"

3.4 S3 Upload Processing

Step 3.4.1: Add Path Generation Function

  1. Add "Function" step
  2. Name: "Generate S3 Path"
  3. JavaScript code:
function main(validation, attachment) { const metadata = validation.metadata; const date = new Date(metadata.timestamp); // Generate organized path structure const year = date.getFullYear(); const month = String(date.getMonth() + 1).padStart(2, '0'); const day = String(date.getDate()).padStart(2, '0'); const hour = String(date.getHours()).padStart(2, '0'); const minute = String(date.getMinutes()).padStart(2, '0'); // Clean sender email for folder name const senderClean = metadata.sender.replace(/[^\w.-]/g, '_'); const subjectClean = metadata.subject.substring(0, 50).replace(/\s+/g, '_'); const basePath = `gmail-attachments/${year}/${month}/${day}`; const folderName = `${hour}${minute}_${senderClean}_${subjectClean}`; return { bucketName: 'your-s3-bucket-name', fullPath: `${basePath}/${folderName}/${attachment.filename}`, metadata: { 'Content-Type': attachment.mimeType, 'X-Gmail-Sender': metadata.sender, 'X-Gmail-Subject': metadata.subject, 'X-Gmail-Date': metadata.timestamp, 'X-Gmail-MessageId': validation.email.id } }; }

Step 3.4.2: Add S3 Upload Step

  1. Add "Amazon S3" integration step
  2. Action: "Put Object"
  3. Configure:
    • Bucket: {{pathGeneration.bucketName}}
    • Key: {{pathGeneration.fullPath}}
    • Body: {{attachment.data}}
    • Content-Type: {{pathGeneration.metadata.Content-Type}}
    • Metadata: {{pathGeneration.metadata}}
  4. Enable auto-retries (3 attempts)

3.5 Multiple Attachments Handling

Step 3.5.1: Add Fan-Out Step

  1. Add "Fan Out" step after validation
  2. Fan Out On: {{validation.processableAttachments}}
  3. Variable Name: currentAttachment

Step 3.5.2: Restructure Attachment Processing

  1. Move attachment extraction, path generation, and S3 upload steps inside Fan-Out
  2. Update references to use {{currentAttachment}} instead of array indexing

3.6 Error Handling & Logging

Step 3.6.1: Add Error Handling Function

function main(s3Upload, pathGeneration, validation) { const result = { success: true, uploadedFile: pathGeneration.fullPath, fileSize: s3Upload.ContentLength || 'unknown', timestamp: new Date().toISOString(), emailId: validation.email.id }; // Log successful upload console.log('File uploaded successfully:', result); return result; }

Step 3.6.2: Add Notification Step (Optional)

  1. Add "Request" step for webhook notification
  2. Or add "Slack" step to notify team channel
  3. Configure with upload summary

3.7 Workflow Optimization Settings

Step 3.7.1: Configure Workflow Settings

Step 3.7.2: Add Conditional Logic

  1. Add "Conditional" step before S3 upload
  2. Condition: {{validation.processableAttachments.length > 0}}
  3. Skip upload if no valid attachments

Phase 4: Testing & Deployment

4.1 Unit Testing Each Step

Step 4.1.1: Test Individual Components

Step 4.1.2: Integration Testing

Send test emails with:

4.2 Performance Testing

Step 4.2.1: Load Testing

4.3 Deployment

Step 4.3.1: Deploy Workflow

  1. Click "Deploy" button in workflow editor
  2. Verify deployment status
  3. Test with live Gmail account

Step 4.3.2: Monitor Initial Operations

Phase 5: Monitoring & Maintenance

5.1 Setup Monitoring

Step 5.1.1: Configure Alerts

Step 5.1.2: Regular Maintenance

5.2 Security Considerations

Important Security Notes

Conclusion

System Benefits

This comprehensive system design provides:

Next Steps

  1. Set up your Paragon account and integrations
  2. Follow the phase-by-phase implementation guide
  3. Test thoroughly with your specific use cases
  4. Deploy to production with monitoring enabled
  5. Iterate based on usage patterns and feedback