Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I need forward 200 email messages. I have a Gmail account and Thunderbird installed. I can't forward each message manually; I want forward them at once. How can I do that?

share|improve this question

migrated from stackoverflow.com Dec 14 '12 at 8:27

This question came from our site for professional and enthusiast programmers.

2 Answers 2

up vote 3 down vote accepted

If the emails have any common feature that you can make a filter out of them, like they are all from one (or few) senders, then create a filter in Gmail and and fill in the address you want to send them to in the "Forward it to:" textbox and select "Also apply filter to X matching conversations."

It will send out the filtered messages right after.

share|improve this answer
    
I just attempted this without success. No messages were sent even though I followed your description exactly. –  David Feb 27 '13 at 2:38
    
Unfortunately it does say that old mail won't be forwarded. Just works for new emails received. –  Niki Oct 1 '13 at 18:01

Gmail's behaviour apparently has changed and the tip in Niki's answer is now inapplicable. I just had this problem and found no real solutions, so here's my Python for anyone who's interested. It is a basic script: headers are not rewritten with great care and it does not handle conversations. To use it, make sure you have IMAP enabled in your account and for the "folders" you want to fetch mail from.

import email
import email.Utils
import imaplib
import os
import smtplib
import tempfile
import time

# Download email.
gmail = imaplib.IMAP4_SSL('imap.gmail.com')
# 'password' can be an app-specific password if two-step authentication is
# enabled.
gmail.login('me@gmail.com', 'password')
print 'Login to IMAP server succeded.'
# Select an appropriate "folder".
gmail.select('[Gmail]/All Mail', readonly=True)
message_ids = gmail.search(None, '(OR FROM "you@gmail.com" TO "you@gmail.com")')[1][0].split()
# Fetch all messages, that might take long. Assumes the message numbers don't
# change during the session.
print 'Fetching email...'
messages = map(lambda x: gmail.fetch(x, '(RFC822)')[1][0][1], message_ids)
print '%d messages fetched' % len(message_ids)
# We're done with IMAP.
gmail.shutdown()

# Parse email content into objects we can manipulate.
messages = map(email.message_from_string, messages)

# I like mail sorted by date. Does not account for different time zones.
messages.sort(key=lambda message: email.Utils.parsedate(message['Date']))
print 'Sorted email.'

# Write email to a directory if you want to inspect the changes from processing
# (read below).
temp_directory_in = tempfile.mkdtemp(suffix='_email')
map(lambda pair: file(os.path.join(temp_directory_in, '%d.eml' % pair[0]), 'w').write(pair[1].as_string()), enumerate(messages))
print 'Unprocessed email saved at \'%s\'.' % temp_directory_in

# Process your messages. Email with third-party addresses in 'to', 'cc', 'bcc',
# 'reply-to', 'in-reply-to' and 'references' fields may be tricky: Gmail
# apparently automatically copies third-party people who appear in some of
# these headers so it might be safer to canonicalize or remove them. Also,
# Gmail does not seem to like email that already contains a message id, so just
# remove this too.
def remove_header(message, header):
  if header in message:
    del message[header]

def remove_headers(message, headers):
  for header in headers:
    remove_header(message, header)

def process_message(message):
  if 'To' in message:
    if 'me@gmail.com' in message['From']:
      message.replace_header('To', '"You" <you@gmail.com>')
    else:
      message.replace_header('To', '"Me" <me@gmail.com>')

  # Gmail will rewrite the 'from' address (not the name!) to match your email
  # address. It will also add a 'bcc' matching the recipient if it is different
  # from the 'to' address.
  remove_headers(message, ['Cc', 'Bcc', 'Reply-To', 'In-Reply-To', 'References', 'Message-ID'])

map(process_message, messages)
print 'Processed email.'

# At this point it may be a good idea to actually peek at you're going to send.
temp_directory_out = tempfile.mkdtemp(suffix='_email')
map(lambda pair: file(os.path.join(temp_directory_out, '%d.eml' % pair[0]), 'w').write(pair[1].as_string()), enumerate(messages))
print 'Processed email saved at \'%s\'.' % temp_directory_out

# If it looks good to you, send it out.
if raw_input('Continue? ') == 'yes':
  gmail = smtplib.SMTP_SSL('smtp.gmail.com')
  gmail.login('me@gmail.com', 'password')
  print 'Login to SMTP server succeded.'

  for index, message in enumerate(messages):
    status = gmail.sendmail('me@gmail.com', 'you@gmail.com', message.as_string())
    print 'Email %d/%d sent (status: %s)' % (index + 1, len(messages), status)
    time.sleep(1)

  gmail.quit()
  print 'All done.'
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.