I couldn't find an add-on for Thunderbird to do this. I did see an add-on that allows you set a future date for an email, but not a past date. I also couldn't find any other simple program or Cygwin command to use. So I just did it with Java and it ended up being rather simple.
The key thing here was preserving the sent date. I tried setting the clock on my machine back in time, but that doesn't really work because I'd have to reset it to a different date and time for each email and that's just too much manual work. My internet connection also doesn't like it when my machine's time is way off from reality.
So my solution was to first, in Thunderbird (my email client), save all of the emails I wanted to resend as .eml files in a folder. Then I wrote this simple program using Java Mail's API to read in the .eml file and to send the email again preserving all of the fields, except the TO address, which I changed based on my needs.
Here's the program:
import java.io.*;
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
public class Eml {
public static void main(String args[]) throws Exception {
String host = "smtp.foo.edu";
String from = "phu@foo.edu";
String to = "bar1@foo.edu, bar2@foo.edu";
Properties props = System.getProperties();
props.setProperty("mail.smtp.host", host);
props.put("mail.transport.protocol", "smtp");
Session mailSession = Session.getDefaultInstance(props, null);
mailSession.setDebug(true);
File emlFile = new File(args[0]);
InputStream source = new FileInputStream(emlFile);
MimeMessage message = new MimeMessage(mailSession, source);
System.out.println("--------------");
System.out.println("To: " + Arrays.asList(message.getAllRecipients()));
System.out.println("From: " + message.getFrom()[0]);
System.out.println("Subject: " + message.getSubject());
System.out.println("Sent Date: " + message.getSentDate());
System.out.println("Body: " + message.getContent());
message.setRecipients(Message.RecipientType.TO, to);
Transport.send(message);
System.out.println("Message sent....");
System.out.println("--------------");
}
}
It takes one argument, the name of the file. I used a simple Cygwin for command to loop through the *.eml files and run this program for each one. I could have added that logic to this Java program, but it was just as quick and easy to do it this way.
There's no error handling here and I used wildcards in the import lines which I usually avoid doing, but this works. I ran with it Java 5.
No comments:
Post a Comment