Automated email forwarding script to migrate messages between Gmail accounts

This is definitely a programming question about automating email migration.

I recently finished school and need to move all emails from my university Gmail account (let’s call it Account A) to my personal Gmail account (Account B). Both are Gmail-powered accounts.

Google recommends using POP/IMAP for this, but it keeps failing with error messages like “A message in your account was listed with an invalid size. It has been left on the server.” This seems to be a common issue that affects many users.

Manual mass forwarding isn’t supported by Gmail directly. I’ve tried using filters to forward emails in batches, but Gmail filters don’t support date ranges and there’s no “select all” option that works reliably.

My programming approach: I want to create an automated script that can:

  1. Log into Account A programmatically
  2. Navigate to the oldest email in the inbox
  3. Loop through each message and:
    • Click the forward button
    • Enter Account B’s email address
    • Send the forwarded message
    • Move to the next email

My coding background includes basic C++, some R scripting, and VBA experience, but I’ve never worked with web automation or browser interaction through code.

What I need help with:

  • Which programming language would be best for this task?
  • What libraries or tools should I use to interact with Gmail’s web interface?
  • Are there any specific techniques for handling Gmail’s authentication and navigation?

Any guidance on the technical approach would be greatly appreciated!

Had the same issue when I switched universities. The IMAP method works, but here’s what actually saved me a ton of time - Google Workspace migration tools. Yeah, I know you’re using personal accounts, but here’s the trick: add your personal Gmail to a basic Workspace trial (14 days free) and use their data migration service. It handles OAuth automatically and runs server-side, so you don’t hit those annoying rate limits that kill API scripts. This tool was literally built for moving huge amounts of email between Gmail accounts while keeping your folders and metadata intact. Takes 10 minutes to set up vs days of coding headaches. Just cancel the trial when you’re done if you don’t need Workspace.

Been there! Had to do the same thing when I switched jobs and needed to migrate my corporate emails. Web automation with Gmail is a nightmare - their security and dynamic loading will fight you every step of the way. Skip the web interface completely and go straight to the Gmail API with Python. Way more reliable and won’t break when Google changes things. You’ll need OAuth2 setup for both accounts, then use messages.list() to grab everything from Account A and messages.insert() to dump it into Account B. The python-gmail-api library makes this pretty easy even if you’re new to it. Plus it keeps all the original message structure and metadata intact - much better than forwarding. Just heads up - you’ll slam into rate limits with big volumes, so build in proper throttling and resumption logic from the start.

Outlook’s perfect for this. Had the same nightmare when our department switched email systems - Gmail’s standard transfer kept dying on large attachments. Set up Account A in Outlook with IMAP, add Account B as secondary. Outlook syncs everything locally first, then you just drag whole folders between accounts. Slower than API methods but rock solid - handles those weird messages that kill automated transfers. Desktop client deals with connection drops and retries automatically. You get a local backup during the process too. Hour to set up, let it run overnight. Way better than babysitting some custom script.

Had this exact issue last year when my company folded and I needed to save years of project emails. The Gmail API works, but I found something better - Google Takeout plus a Python IMAP script. Export everything from Account A using Takeout (gives you clean .mbox files), then use Python’s imaplib to push those messages into Account B through IMAP. Skips all the forwarding headaches and keeps original timestamps and sender details. You’re working with actual email files instead of fighting Google’s constantly changing web interface. About 100 lines of Python handles big volumes way better than API calls. Labels don’t transfer perfectly, but all the important email data survives.

selenium webdriver’s probably your best bet coming from vba. it’s clunky but you can automate browser clicks just like a person would. throw in some random delays between actions or gmail will catch the automation and lock you out.

The Problem: You want to automate the migration of emails from one Gmail account (Account A) to another (Account B), and you’re looking for a solution that avoids the complexities of web automation and Gmail API limitations. You’re frustrated with error messages related to invalid email sizes and the limitations of Gmail’s built-in filtering and forwarding capabilities.

TL;DR: The Quick Fix: Use Latenode to migrate your emails from Account A to Account B without writing any code. Latenode handles the complexities of Gmail API interaction, authentication, and rate limiting, providing a reliable and straightforward solution.

:thinking: Understanding the “Why” (The Root Cause):

Manually migrating a large number of emails from one Gmail account to another is tedious and prone to errors. Methods like using Gmail’s built-in forwarding features or writing scripts to interact with the Gmail web interface are complex, time-consuming, and susceptible to breaking due to changes in Gmail’s structure or security policies. Furthermore, dealing directly with the Gmail API often involves navigating rate limits and authentication complexities. Using a dedicated service like Latenode offers a streamlined, reliable alternative that simplifies this process significantly.

:gear: Step-by-Step Guide:

Step 1: Sign up for Latenode. Create a free account at https://latenode.com (or replace with actual link if different).

Step 2: Connect your Gmail Accounts. Within the Latenode interface, follow their instructions to connect both your source (Account A) and destination (Account B) Gmail accounts. This usually involves granting Latenode appropriate OAuth permissions.

Step 3: Initiate the Migration. Configure the migration parameters within Latenode, specifying the source and destination accounts, and any filtering options you might require (e.g., specific labels, date ranges). Latenode’s interface should guide you through this setup.

Step 4: Monitor the Progress. Latenode will typically provide a progress indicator showing the number of emails processed and the overall status of the migration.

Step 5: Verify Completion. Once the migration completes, check your destination account (Account B) to ensure all your emails have been successfully transferred.

:mag: Common Pitfalls & What to Check Next:

  • OAuth Permissions: Double-check that you’ve granted Latenode the necessary permissions to access both your Gmail accounts. Insufficient permissions will prevent the migration from working.
  • Rate Limits (although handled by Latenode): While Latenode manages rate limits, extremely large inboxes might still take significant time to migrate.
  • Unexpected Errors: If you encounter any errors during the process, check Latenode’s documentation or contact their support for assistance. They should provide detailed logs or error messages to help you troubleshoot.

:speech_balloon: Still running into issues? Share your (sanitized) config files, the exact command you ran, and any other relevant details. The community is here to help! Let us know if you’re trying to use Latenode for this!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.