Forward emails via C# SMTP client and keep time stamps and delivery time

1k views Asked by At

I wrote a C# client to download emails from my POP3 mailbox and forward them to my internal exchange server via SMTP.

The code below is working. But the time stamps and delivery time information from the original email are overwritten hence lost because this code will create a complete new email.

Is there any chance to forward emails without loosing the time stamp information from the original email?

using (SmtpClient smtp = new SmtpClient())
{
    smtp.Connect(connectionServer["ExchangeServer"], 25);
    try
    {
        smtp.Ehlo(connectionServer["ExchangeServer"] + "." +
            connectionServer["ExchangeServerDomain"] + ".local");
    }
    catch
    {
        success = false;
        smtp.Helo(connectionServer["ExchangeServer"] + "." +
            connectionServer["ExchangeServerDomain"] + ".local");
    }
    smtp.MailFrom("");
    smtp.RcptTo(popReceipient);
    smtp.DataFromFile(path);
    smtp.Disconnect();
}
2

There are 2 answers

1
Crabax On

It's not possible. Another option would be to use OpenPop.Net to send a separate email with the original email attached as a "*.eml" file that can be open with most email clients. I can post some code if this approach is useful for you.

0
Max On

Can you access your destination server via IMAP?

If so, you can append the mail to your INBOX folder with arbitrary time stamps. If you can access your source server via IMAP, you can actually get the INTERNALDATE as well to use as the timestamp.