I tried to accomplish this via a MailMessage.Headers.Set call, in VB.net. See below:
Dim objMail As MailMessage
Dim objSMTPClient As SmtpClient
objMail = New MailMessage()
objSMTPClient = New SmtpClient()
objMail.From = New MailAddress(MY_EMAIL_ADDRESS)
objMail.To.Add(New MailAddress(TEST_EMAIL_ADDRESS))
objMail.Headers.Set("Date", "09 Jan 1999 17:23:42 -0400")'date in the past'
objMail.Subject = "The Subject"
objMail.Body = "The Body"
objSMTPClient.Port = 25
objSMTPClient.Host = HOST_IP
objSMTPClient.Credentials = New System.Net.NetworkCredential(MY_EMAIL_ADDRESS, txtPassword.Text)
objSMTPClient.Send(objMail)
I confirmed that the objMail.Headers.Set call is actually working - if I get the value afterwards, it has been successfully changed. My problem is that when I receive the e-mail in the TEST_EMAIL_ADDRESS's Outlook, the date is 2009 everywhere, not 1999. Right there in the Outlook interface, and also in the header, which I access via the "Options" item in the context menu for that e-mail.
What am I doing wrong? I have a feeling I missed something obvious...
To be clear: I am not doing this with malicious intent. I am working on an e-mail integration component that utilizes both UIDs and a "Last processed" date to locate the first new e-mail to integrate. I want to test cases where multiple e-mails have the exact same date/time - as the e-mail integration module should handle those situations flawlessly. If I could simply fake the date this way, I could send as many e-mails as I wanted that matches a certain date/time, rather than trying to send them with an automated script - hoping they will all be received within the same second. It seems I'll need to take another approach, though.