vbaemailoutlook

Check if delay delivery is already set


How to delay email delivery through VBA is addressed here, here, here, and here for example.

I implemented a version in Application_ItemSend. 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.

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

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

My code has determined that a delay delivery is required and applied one for 6:31am today.
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 a date-formatted Outlook code that means "no delay delivery is set" or is that a date, set very far out so 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?

Is there a better way to determine if delay delivery has already been set?


Solution

  • 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.