0

I am testing if deferred delivery time works and see that these emails are not sent. I see nothing in the outbox. Emails do get sent if i just .Send and comment out .DeferredDeliveryTime. Also, I've tried manually changing Do not deliver before time in Outlook and that does work. So I am not sure what is going wrong here with the VBA.

Option Explicit

Private Sub CommandButton1_Click()

Dim olApp As Outlook.Application
Dim olMail As Outlook.MailItem
Dim olAccount As Outlook.Account

Set olApp = New Outlook.Application
Set olMail = olApp.CreateItem(olMailItem)

With olMail

.To = "my email"
.Subject = "test"
.Body = "test"

' .Send
 .DeferredDeliveryTime = DateAdd("n", 10, Now)
End With

End Sub
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
navneesi
  • 21
  • 1
  • 6
  • Figured I also need to add `.Send` after `.DeferredDeliveryTime`. The examples here - http://www.vboffice.net/en/developers/send-delay/ do not do that. – navneesi Oct 26 '18 at 02:12
  • The examples below are changing the `Application_ItemSend` function, so I don't think this works like you think it does – Marcucciboy2 Oct 26 '18 at 02:42
  • https://stackoverflow.com/a/41318693/4539709 – 0m3r Oct 26 '18 at 07:22
  • I added `.Send` after ``.DeferredDeliveryTime = DateAdd("n", 5, (DateAdd("h", -5.5, Now)))`` but now all emails are being sent immediately. Not sure why. I am using ``(DateAdd("h", -5.5, Now)`` in `Now`'s place to adjust for the time zone. Outlook is using UTC time zone by default which i need to convert to local time zone. – navneesi Oct 27 '18 at 22:06
  • There's no need to change the time zone. When manually changing the Delay Delivery do not send before time, I had to change the time to UTC. Don't need to do this in VBA apparently. – navneesi Oct 28 '18 at 00:02

1 Answers1

2

According to my test, You should change .DeferredDeliveryTime = DateAdd("n", 10, Now) Position, like this:

Dim olAccount As Outlook.Account

Set olApp = New Outlook.Application
Set olMail = olApp.CreateItem(olMailItem)

With olMail
.To = "email address"
.Subject = "test"
.Body = "test"
.DeferredDeliveryTime = DateAdd("n", 10, Now)
.Send

End With

End Sub

This code is run success in my PC.

Alina Li
  • 884
  • 1
  • 6
  • 5
  • Thanks. Adding `.Send` is what I was missing. `.DeferredDeliveryTime = DateAdd("n", 10, Now)` does not send the email. – navneesi Nov 01 '18 at 02:31
  • .DeferredDeliveryTime will delayed send email. Have you been waiting for some time? Please refer to this link: https://learn.microsoft.com/en-us/office/vba/api/outlook.mailitem.deferreddeliverytime – Alina Li Nov 01 '18 at 02:54
  • .DeferredDeliveryTime = DateAdd("n", 10, Now) will send email after ten minutes. For more information, please refer to this link: https://stackoverflow.com/questions/41297105/how-can-i-automatically-send-an-email-with-delay-from-an-outlook-inbox-usign-vba – Alina Li Nov 01 '18 at 02:58