email_organization
This is an old revision of the document!
<!DOCTYPE html> <html> <head>
<title>Automated Gmail-to-PDF Archiving System</title> <style> body { font-family: Arial, sans-serif; background: #fefefe; padding: 40px; color: #333; line-height: 1.6; } h1, h2 { color: #2a2a2a; } code { background: #f4f4f4; padding: 2px 6px; border-radius: 3px; font-size: 90%; } ul { margin-top: 0; } </style>
</head> <body>
<h1>Automated Gmail-to-PDF Archiving System</h1>
<h2>Purpose</h2> <p>This system automatically searches Gmail for emails sent <strong>to or from specific contacts or domains</strong>, converts them into PDFs, and stores them in named folders in Google Drive. It's used to keep a searchable, organized, and timestamped record of key communications for future reference, especially across insurance and claim-related projects.</p>
<h2>What It Does</h2> <ul> <li>Searches Gmail for all emails <strong>to or from</strong> a specific sender or domain.</li> <li>Converts each email into a timestamped <code>.pdf</code> file using Google Apps Script.</li> <li>Stores the PDFs in organized folders within Google Drive, named after the contact or domain.</li> <li>Filenames are standardized: <code>YYYY-MM-DD - TO/FROM email@domain.com - Subject.pdf</code></li> </ul>
<h2>How It Works</h2> <ol> <li>Create a new <a href="https://script.google.com" target="_blank">Google Apps Script</a> project.</li> <li>Paste the provided script for the desired sender/domain (see examples below).</li> <li>Run the script and authorize permissions when prompted.</li> <li>The script will auto-create a Drive folder (if not existing) and populate it with generated PDFs.</li> </ol>
<h2>Script Template</h2> <p>Replace <code>@example.com</code> or <code>user@example.com</code> with your target domain or address:</p>
<pre><code>function archiveAllEmailsWithDomain() { var domain = "@example.com"; var threads = GmailApp.search("from:" + domain + " OR to:" + domain);
var folderName = "Gmail PDFs - Example (All Emails)"; var folders = DriveApp.getFoldersByName(folderName); var folder = folders.hasNext() ? folders.next() : DriveApp.createFolder(folderName);
for (var i = 0; i < threads.length; i++) { var messages = threads[i].getMessages(); for (var j = 0; j < messages.length; j++) { var msg = messages[j]; var sender = msg.getFrom(); var recipient = msg.getTo(); var date = Utilities.formatDate(msg.getDate(), "GMT", "yyyy-MM-dd"); var subject = msg.getSubject().replace(/[^a-zA-Z0-9 ]/g, '').substring(0, 50);
var direction = sender.includes(domain) ? "FROM" : "TO"; var contact = sender.includes(domain) ? sender : recipient; var contactClean = contact.match(/<(.+)>/) ? contact.match(/<(.+)>/)[1] : contact;
var filename = `${date} - ${direction} ${contactClean} - ${subject}.pdf`; var blob = Utilities.newBlob(msg.getBody(), "text/html", filename).getAs("application/pdf");
folder.createFile(blob); } }
}</code></pre>
<h2>Configured Examples</h2> <ul> <li><strong>Shari Bradix (specific address):</strong> <code>Shari.Bradix@cna.com</code></li> <li><strong>All CNA contacts:</strong> <code>@cna.com</code></li> <li><strong>All J.S. Held engineers:</strong> <code>@jsheld.com</code></li> <li><strong>Bockmon Insurance:</strong> <code>@bockmoninsurance.com</code></li> </ul>
<h2>Next Steps (Optional)</h2> <ul> <li>Add automatic scheduling to run these scripts daily/weekly.</li> <li>Enhance script to export attachments or summarize content with AI.</li> <li>Back up Drive folders to external storage/cloud systems.</li> </ul>
</body> </html>
email_organization.1742676543.txt.gz · Last modified: 2025/03/22 20:49 by lwattsii