如何从.NET发送过去日期的电子邮件? [英] How can I send an e-mail with a past date from .NET?

查看:169
本文介绍了如何从.NET发送过去日期的电子邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过一个MailMessage.Headers.Set调用,在VB.net中完成这个。见下文:

  Dim objMail As MailMessage 
Dim objSMTPClient As SmtpClient

objMail = New MailMessage()
objSMTPClient =新的SmtpClient()

objMail.From =新的MailAddress(MY_EMAIL_ADDRESS)
objMail.To.Add(新的MailAddress(TEST_EMAIL_ADDRESS))
objMail.Headers.Set(Date,1999年1月9日17:23:42 -0400)'过去的日期'

objMail.Subject =主题
objMail .Body =The Body

objSMTPClient.Port = 25
objSMTPClient.Host = HOST_IP
objSMTPClient.Credentials =新建的System.Net.NetworkCredential(MY_EMAIL_ADDRESS,txtPassword.Text)
objSMTPClient.Send(objMail)

我确认objMail.Headers.Set调用是实际工作 - 如果我以后获得价值,它已经被成功地改变了。我的问题是,当我在TEST_EMAIL_ADDRESS的Outlook中收到电子邮件时,日期是2009年,而不是1999年。在Outlook界面中,还有在标题中,我通过上下文中的选项项目访问该电子邮件的菜单。



我做错了什么?我有一种感觉,我错过了一些明显的东西...



要明确:我不是恶意使用这个做法。我正在使用一个电子邮件集成组件,它利用UID和最后处理日期来定位首个新的电子邮件集成。我想测试多个电子邮件具有完全相同的日期/时间的情况 - 电子邮件集成模块应该完美地处理这些情况。如果我可以这样假装日期,我可以发送尽可能多的电子邮件,我想要匹配一个特定的日期/时间,而不是试图用自动脚本发送他们 - 希望他们将在同一秒内收到。看来我需要采取另一种方法。

解决方案

添加到@Lasse V. Karlsen的笔记,我认为最有可能的是,SMTP服务器覆盖了你放入代码中的消息。老实说,你为甚么需要像过去一样发送邮件呢?我不能想到一个至少是不诚实的单一原因,至少是恶意的。



所以,对我来说,服务器会覆盖这一点标题如果看起来很可疑我不知道这是真的发生了什么,但我敢打赌@Lasse V. Karlsen是正确的。



如果是这样,一个可能的解决办法是改变日期在SMTP服务器上过去某个日期(如果您控制服务器并能够这样做)。



仍然,我想知道为什么你会想甚至这样做。您可以详细说明吗?



添加



@Lasse V. Karlsen - 我想您应该将您的笔记发布为答案,以便您获得信用。


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.

解决方案

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.

这篇关于如何从.NET发送过去日期的电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆