C# .EML resending with new Address - Date Issue

589 views Asked by At

The main requirement I am fulfilling is to read through millions of old emails and post them into our new system for proper archiving. The task itself is to read the .eml file, and add a new BCC email address and then drop the new email file into a specific SMTP server which is routed to a smart-host which then archives the email without it going into the real world.

The problem is, when i call the .Send() method, the date stamp is the current date, and not the date of the original email. I have tried using both Smtp.MailMessage and CDO.Message. neither seem to have any type of "date" property which is settable, as CDO.MessageClass has a SentOn which is read only. Is this something possible within the standard frameworks that I am missing, do I need to implement my own MessageClass,or should i manually modify the existing .eml file as a text file, or use an alternative such as Afterlogic MailBee?

Note: this is not malicious intent to try and back-date an individual email, this is a real world project. I have searched other threads such as the one below which i cannot seem to find an answer. How can I send an e-mail with a past date from .NET?

1

There are 1 answers

1
Mike Zboray On BEST ANSWER

This is fairly straightforward using the MimeKit package:

string outputDirectory = "out"; // or whatever the output path is
foreach (var file in Directory.EnumerateFiles(workingDirectory, "*.eml"))
{
    var message = MimeMessage.Load(file);
    message.Bcc.Add(new MailboxAddress("[email protected]"));
    string outputFile = Path.Combine(outputDirectory, Path.GetFileName(file));
    message.WriteTo(outputFile);
}