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.
Change the Date & Time on Your Computer. One very basic way to send an email with a previous date is to change your PC's clock to the time you are trying to simulate before sending the email. Some older email clients like Outlook Express will accept this date and send it to the email server with the local date and time ...
Delay the delivery of a message While composing a message, select the More options arrow from the Tags group in the Ribbon. Under Delivery options, select the Do not deliver before check box, and then click the delivery date and time you want. Click Close. When you're done composing your email message, select Send.
Altering Timestamps: To make an email appear in the recipient's folder in a different time order, or to change the timestamp on your copy pushed into your sent folder, you can simply temporarily change the clock on your personal computer, and then send the message from commonly used email programs like Microsoft ...
Select the email you want to change. At the top right of your email, click Cancel send. Create your changes. Click Schedule send and select a new date and time.
Adding on to @Lasse V. Karlsen's note, I think that most likely the SMTP server is overriding what you put into the message in code. In all honesty, why would you even need to make an email look like it was sent in the past? I can't think of a single reason that isn't dishonest at least or malicious at worst.
So, it would make sense to me that the server would overwrite this header if it looked suspicious. I don't know if that's what's actually happening, but I would bet that @Lasse V. Karlsen is correct.
If so, a possible solution would be to change the date on the SMTP server to some date in the past (if you control the server and are able to do so).
Still, I am wondering why you would want to even do this. Can you elaborate?
Added
@Lasse V. Karlsen - I think you should post your note as the answer so you get the credit for it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With