英文:
Outlook VBA: Check if delay delivery is already set
问题
在Outlook中通过VBA编程如何延迟电子邮件传送的问题已经在以下位置得到了很好的解答1,2,3和4。
我已经在Application_ItemSend
中实现了一个版本,基本上满足了我的需求。但是现在,如果电子邮件在某个特定的时间之前发送,它总是应用延迟传送。
**我如何检查是否已经设置了延迟传送?**在这种情况下,我可能选择不更改它,或者将已设置的日期/时间与一些较早的允许时间进行比较等。
为了尝试弄清楚这个问题,我在我的代码之前和之后打印了Item.DeferredDeliveryTime
:
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Debug.Print "Item.DeferredDeliveryTime: " & Item.DeferredDeliveryTime
' 我的延迟传送代码在这里。
Debug.Print "Item.DeferredDeliveryTime: " & Item.DeferredDeliveryTime
End Sub
当我在一封新的电子邮件上运行这个代码时,所以在开始时延迟传送没有设置,我得到了以下结果:
Item.DeferredDeliveryTime: 4501-01-01
Item.DeferredDeliveryTime: 2023-07-20 6:31:00 AM
因此,我的代码已经确定需要延迟传送,并且已经应用了一个在今天早上6:31的延迟传送。但在这之前,Item.DeferredDeliveryTime
被设置为一个奇怪的数字4501-01-01,看起来像一个没有时间的日期。
那个初始数字只是一个日期格式化的Outlook代码,表示“未设置延迟传送”吗?还是那是一个实际日期,设置得非常遥远(在这种情况下大约2500年),以便Outlook忽略它?
无论哪种情况,那个数字是恒定的吗?也就是说,所有系统上的所有电子邮件在任何时候都会在延迟传送未设置时显示相同的数字吗?这意味着我可以将该值与该恒定值进行比较。还是它是可变的,需要一些解析来确定它是否是“非常遥远”的日期,如果是这样,我们将假定未设置延迟传送?
或者,我是否走错了方向,有更好的方法来确定是否已经设置了延迟传送,而不是查看Item.DeferredDeliveryTime
?
谢谢。
英文:
The question of how to delay email delivery programmatically in Outlook through VBA is already well addressed here, here, here, and here for example.
I've implemented a version in Application_ItemSend
that mostly suits my needs. But right now it always applies a delay delivery if the email is being sent before a certain time of day.
How do I check if delay delivery is already set? In which case I might opt not to change it, or to compare the already-set date/time against some earlier allowed time or whatever.
To try to figure this out, I printed Item.DeferredDeliveryTime
before and after my code that adds delay delivery:
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Debug.Print "Item.DeferredDeliveryTime: " & Item.DeferredDeliveryTime
' My code to delay delivery is here.
Debug.Print "Item.DeferredDeliveryTime: " & Item.DeferredDeliveryTime
End Sub
When I run this on a fresh email, so delay delivery is not set at the beginning, I get the following:
Item.DeferredDeliveryTime: 4501-01-01
Item.DeferredDeliveryTime: 2023-07-20 6:31:00 AM
So my code has determined that a delay delivery is required and applied one for 6:31am today. But before doing that, the Item.DeferredDeliveryTime
was set to this strange number 4501-01-01 that looks like a date with no time.
Is that initial number just a date-formatted Outlook code that means "no delay delivery is set"? Or is that an actual date, set very far out (~2500 years in this case) so that Outlook ignores it?
In either case, is that number constant? I.e. will all emails on all systems at all times show the same number when delay delivery is not set? Meaning I can just check the value against that constant. Or is it variable, requiring some parsing to determine if it's a "very far away" date, in which case we'd assume delay delivery is not set?
OR, am I heading down the wrong path and there is a better way to determine if delay delivery has already been set than looking at Item.DeferredDeliveryTime
?
Thanks.
答案1
得分: 1
由于DateTime
不可为空(它是COM中的8字节浮点数),唯一指定“无值”的方法是使用特殊值,即1/1/4501
。Outlook始终对其未设置的DateTime属性使用该值。
英文:
Since DateTime
is not nullable (it is an 8 byte float in COM), the only way to designate "no-value" is to use a special value, which is 1/1/4501
. Outlook always uses that value for its DateTime properties that are not set.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论